I hope you are well !!
My database looks like below:
/ CLASSROOM1 [collection] ----> DATAS [document] ----> USERS [collection] ----> userdId [document] ----> [user data (field)]
/ CLASSROOM2 [collection] ----> DATAS [document] ----> USERS [collection] ----> userdId [document] ----> [user data (field)]
/ CLASSROOM3 [collection] ----> DATAS [document] ----> USERS [collection] ----> userdId [document] ----> [user data (field)]
I would like to know if it is possible to search the entire Firestore database (CLASSROOM1, CLASSROOM2, CLASSROOM3 ...) and find the correspondence with the "matricule" entered by the user.
The goal here is to find the field "matricule" found in the document "userId" and to read its value, so as to know which user it belongs to.
Thank you. I start on Firestore
I don't think this would be efficient. As #Doug mentioned above, each collection will require it's own query which would ofcourse empty your pocket.
Best way to do this would be create a different collection which contains the matricule as documents and store the {user id} in that document per user. Then when you want to fetch the data, query this new collection to get the {user id}. You know what the user ID is, now you fetch anything regarding that user in your Firestore Database.
It's not possible to perform a single query across multiple collections with different names. Each collection will require its own query, and you will have to merge the results from those queries on the client.
The only type of query that can use multiple collections is a collection group query, which requires that each subcollection must have the same name.
I assume you have userId as input and wnat the corresponding matricule. Add "userId" as a field, then you can do a collection group query on the collections "USERS"
collectionGroup("USERS").where("userId", "==", userId)
Related
I am trying to fetch data with specific name from a google spreadsheet using java. I am able to fetch complete data from a column using google api. I specify range as "sheet1!B:B" for example. However, I am not understanding
How to fetch data from multiple columns. How should I pass the range?
How do I specify the data filter for columns.
Any guidance would be really appreciated. I am unable to find it in github or googlespreadsheet api docs. Please help me out
Currently I have code to fetch all values from googlespread sheet using below code
String spreadsheetId="spreadseet id";
String range="Sheet!A2:zz";
Sheets service = new Sheets.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
Sheets.Spreadsheets.Values.Get request=service.spreadsheets().values().get(spreadsheetId, range);
ValueRange response = request.execute();
Let's take the official example provided by google here:
How to fetch data from multiple columns. How should I pass the range?
This is the range:
String range = "Class Data!A2:F";
Which means fetch all the data from the cell A2 to the column F of the sheet with the name Class Data.
How do I specify the data filter for columns.
Once you have all the data you can filter it in a normal for-loop. For example if we want only the column 1 and 2:
List<List<Object>> values = request.execute().getValues();
System.out.println("Name, Gender");
for (List row : values) {
System.out.println(row.get(0)+", "+row.get(1));
}
The output will be:
Name, Gender
Alexandra, Female
Andrew, Male
Anna, Female
More info on the official Java Quickstart.
You can try using RestedBox to access your Google Sheets and local spreadsheet data through an API, including querying. I've been using it for some POC's instead of a database.
Image 1 is the current data,
Image 2 is the data i need to store into a new table. Thing is i want to combine all the same ITEM_NO and put it as a comma separated value and insert into a new table.
Whilst I don't think storing data like this is a good idea at all (see what others have said in the comments) it is possible by doing:
SELECT REFERENCE_NO,
ITEM_NO,
ROLES = STUFF((SELECT N', ' + ENTITY_ROLE
FROM dbo.MyTable AS p2
WHERE p2.ITEM_NO = p.ITEM_NO
ORDER BY ENTITY_ROLE
FOR XML PATH(N'')), 1, 2, N'')
FROM dbo.MyTable AS p
GROUP BY REFERENCE_NO, ITEM_NO
ORDER BY ITEM_NO;
A demo of this in action: SQL Fiddle
I have the following models
categories(id, name)
places(id, name, category_id)
i have a list view which displays Content based on the categories the user wants to see.
Data for Categories
1, River
2, Hill Station
3, Wild Life
4, Temples
If the user wants to see places of only category_id = 2 and 4.
How can i do a query to the database to give back a list of places which have category_id = 2 and 4.
I am using stORM library for the Database.
They have the following functions to do a query.
dao.listAll();
dao.listByExample(exampleObj);
If you switch to greenDAO, you can use a QueryBuilder, which supports IN and the likes:
http://greendao-orm.com/documentation/queries/
I use ormlite for this purpose. Check out section in the docs about the query-builder.
I am trying to construct a DTO object to ferry the data from data layer to view layer.
The data is as follows:
There are 7 days(dates can be used as a key in Map or any other datastructure)
The individual dates will contain multiple records.
Each record contains contact details obtained from multiple tables.
One record needs to be constructed from 3 rows in the result table. ie:
A record may return three rows with same values for all columns except for the user details; which contains details like id,name and designation.
When I display, I need to show their name as Manager and assistant manager in the same row.
Data Layer
T01 25/12/2012 ABC XYZ Manager
T01 25/12/2012 ABC IJK Asst.manager
Display:
Date 1
TaskID Taskdeadline TaskGivenBy Task assigned to Manager Task Assigned toAsst.Manager
T01 25/12/2012 ABC XYZ IJK
T02 1/1/2013 BCE WUV MNO
Solution I tried:
Map<Date,Map<Position,Object>>
Map<25/12/2012,Map<(Manager,Object details),(Asst Manager,Object details)>
and then repeat it. But I guess I am storing duplicate data. I don't think this is an ideal solution
I have 4 tables involved in this query.
Campaign - many to one business
Business - one to many client
Client - one to one contact
Contact
In contact there is the field contact_name which is unique. I need to retrieve all campaigns related to contact(via client and business) which campaign field type equals 2.
What is the best way to do it with hibernate?
In SQL is will look like this:
select *
from campaign,contact, business, client
where campaign.type=2
and client.contact_id = contact.contact_id
and contact.name = 'Josh'
and client.business_id = business.business_id
and campaign.campaign_id = business.business_id
I think that the following should work.
from Compaign where Compaign.type=2 and compaign.business.client.contact.contact_name=:name
You can execute native SQL Queries too using createSQLQuery() method of Session.
You can also use Scalar Property to avoid the overhead of using ResultSetMetadata.
You can find more information on this from here