Trying to get the data from specific document from firestore.
database have First collection named "learner" and in each document of this another collection "request".
(each document is created with the same name as email)
so each document have emails as their name.
when im using a static address i get the correct response .
but of course the addressing i need to get is with the email which user will input,
Firestore.instance.collection("/learner/Qwr4#g.com/requests/").snapshots().listen(Elements);
Elements is the function which converts the response into a list
using this function i get correct response
but what i need is
this is what is need.
this function is giving me list of 0 length
void function(String email) { Firestore.instance.collection("learner").document(email).collection("requests").snapshots().listen(Elements); }
Related
I'm wondering if there is a common solution/pattern for the following situation:
Let's say I have a webshop application. There you can create orders, which consists of items. Each order item can have one or more files as attachments. (May not make sense, but it's just an example). Pseudocode:
Order
{
Guid Id
List<OrderItem> Items
}
OrderItem
{
Guid Id
List<Attachment> Attachments
}
Attachment
{
Guid Id
string Filename
byte[] Content
}
The technology is ASP.Net MVC + React. When creating an order, I cannot send the files in the same request due to request length limits. So I have to first send a request to create an order, and then send the files one by one. How do I get the correct OrderItem id (in frontend) for each attachment?
When creating an order, none of the items have ids. CreateOrder method returns the created order and items with ids, but how can I map items in the result to items in the request that don't have ids? Result items may even be sorted differently.
One option could be to add a separate id field to OrderItem dto, e.g. NewItemId. In that case, that id would be generated by the frontend and returned by the backend in the result. However, due to how the application is structured, that would require including the property in a domain class. Is there any more elegant solution?
Im trying to create one stream, that is using multiple documents references that are stored and fetched from Firebase Firestore.
Lets say I have two collection named users and documents. When user is created he gets document with his id in users collection with field named documentsHasAccessTo that is list of references to documents inside documents collection. It is important, that these documents can be located in different sub collections inside documents collection so I dont want to query whole documents and filter it, in order to save Firestore transfer and make it faster I already know paths to documents stored in documentsHasAccessTo field.
So for example, I can have user with data inside users/<user uid> document with documentsHasAccessTo field that stores 3 different document references.
I would like to achieve something like this (untested):
final userId = 'blablakfn1n21n4109';
final usersDocumentRef = FirebaseFirestore.instance.doc('users/$userId');
usersDocumentRef.snapshots().listen((snapshot) {
final references = snapshot.data()['documentsHasAccessTo'] as List<DocumentReference>;
final documentsStream = // create single query stream using all references from list
});
Keep in mind, that it would also be great, if this stream would update query if documentsHasAccessTo changes like in the example above, hence I used snapshots() on usersDocumentReferences rather than single get() fetch.
The more I think about this Im starting to believe this is simple impossible or theres a more simple and clean solution. Im open to anything.
You could use rxdart's switchMap and MergeStream:
usersDocumentRef.snapshots().switchMap((snapshot) {
final references = snapshot.data()['documentsHasAccessTo'] as List<DocumentReference>;
return MergeStream(references.map(ref) => /* do something that creates a stream */));
});
I want to do something like:
final collectionReference = Firestore.instance.collection('myCollection');
final List<String> documentList = collectionReference.getDocList();
OR
final query = collectionReference.orderBy('lastUpdated', descending: true).limit(100);
final List<String> documentList = query.getDocList();
Currently when we use get() or query.getDocuments() it will return the whole Document list and all contents along with it. But you know that we wanna optimize reads thus we make use of the 1MiB limit of each Documents. Thus we don't wanna download the whole document's contents. Rather we just need the IDs for other usage. Is there a way to do this ?
Thanks
There no way to do this with the Flutter APIs (or any of the web or mobile clients).
The only way is with backend code, where you have a method like select() (link to the nodejs API) on Query that lets you select which document fields to return. So, you could have your app call a backend to return the document IDs, but not directly in the app.
If you must query from the client, consider moving fields unnecessary for queries to documents in anther collection with the same IDs, and request them only when needed.
My data looks like below,
"USERS": { "JACK": { "FirstName":"Jack", "LastName":"Wil" }, "JAY": { "FirstName":"Jay", "LastName":"Martin" } }
I'm writing a HTTPS triggered cloud function that first sends Node names (JACK, JAY) and then based on selection, sends details.
For sending the Node names, I'm just wondering if there is any way/function to get all the Node names under a Child without iterating through the snapshot and collecting the names using '.key'
I have gone through the below posts, but they discuss the iteration logic. So posting a new question.
Getting node names from Firebase database based on emailId match
Getting node names from Firebase database based on emailId match
Currently I can't seem to find a way to delete an object from firebase list via REST api. For example I am trying to remove this from the list:
https://mrdapper.firebaseio.com/v0/users/41/favs.json?orderBy=%22id%22&equalTo=107657061
Posting a DELETE request doesn't work with query parameter.
You can't delete with a query, (although that would be awesome). But you can use the results to send a DELETE request.
Do a GET:
GET https://mrdapper.firebaseio.com/v0/users/41/favs.json?orderBy=%22id%22&equalTo=107657061
This will return the object and you can send a DELETE request for each item it returns.
DELETE https://mrdapper.firebaseio.com/v0/users/41/favs/<returned-id>.json
Now, you may not like sending one delete request per object. But, with your data structure this is necessary.
If you'd like to easily query and delete items, you could try this data structure:
/users/$user_id
/userFavs/$user_id/$fav_id
Store the favs in it's own location under the root. This will allow you to retrieve user data without always getting the favs.
For userFavs if you key off userid and the favid you can easily query and delete.
{
"userFavs": {
"41": {
"107657061": {
"note_count": 43633
}
}
}
}
Now you can easily get all of the the user's favorites by specifying the user's id. If you need to delete by an id, that is also a key. So you can now DELETE without querying.
DELETE https://mrdapper.firebaseio.com/v0/userFavs/41/107657061.json