Fetch specific data from Firestore in Flutter [duplicate] - flutter

This question already has answers here:
Firestore - get specific fields from document
(4 answers)
Closed 12 days ago.
There is a database named userdetails of three columns name, email, and password. How can I fetch only name from Firebase Firestore? Please give an example.
I have stucked in that thing(fetching of specific data)

As far as I am aware, you can't do that with a server side query. A firebase query would return the DocumentSnapshot.
On the client side you would map that to what you need.
https://firebase.google.com/docs/firestore/query-data/get-data

Related

Is there a way of adding the document's ID to the document itself upon its creation on Firestore? [duplicate]

This question already has answers here:
How to save the document id in document field while creating it in Flutter Firebase
(2 answers)
How to add document Id in the document in firestore database in flutter application
(2 answers)
Closed 4 months ago.
In my local model, I do carry the document's Firestore's ID, however that's something I know how to get only after the document's creation. So currently, I have to also manage a version of the model where the ID might not be there or might be optional.
I know, though, that, for example, there's a way of preemptively adding the server timestamp from the client to Firestore:
await collection.add({
'timeOfCreation': Fieldvalue.serverTimestamp()
});
And I know there's a thing called FieldPath. However, this seems to not be working:
await collection.add({
'timeOfCreation': Fieldvalue.serverTimestamp(),
'id': FieldPath.documentId
});
(And neither is FieldPath.document(), it's a property after all...)
Is there a way of doing this currently on Firestore? (If not, why not?!)

How do I get and store document ID to Field in flutter [duplicate]

This question already has answers here:
How do I get documentid of a firestore document in flutter?
(7 answers)
Closed 9 months ago.
How can I get the document ID and store it in field, such as the document ID marked in red, and store in post_pid
You can do something like this while adding your data.
const postDocRef=firebaseClient.firestore().collection('post_details').doc();
await postDocRef.set({
post_pid: postDocRef.id,
// ....rest of your data
});
We get a document reference first and then we get the id property.

Firebase where query (not include) [duplicate]

This question already has answers here:
Firestore - Possible to query by array-not-contains?
(4 answers)
Firestore get documents where value not in array?
(4 answers)
Closed 1 year ago.
I have a firestore collection with many document and all these documents include an array field (called "notFor") with a list of uid. In some cases the array contains only 1 value in some other cases it contains more than 1 value. Example
docA
notFor: "userB", "userC"
docB
notFor: "userB"
docC
notFor: "userA", "userC"
Is there any suggestion on how I could find a document in that collection that does not include "userB"? I basically would like to find docB by excluding all the docs where userC is present
I am writing in flutter however this is not so relevant for this case, I am just interested to understand if I can do something like this with the firestore operators.
thanks!

How to fetch the data on the basis of multiple ids? [duplicate]

This question already has answers here:
Querying mongodb from golang using the _id stored in an array
(3 answers)
Find by id with mgo
(1 answer)
Closed 4 years ago.
Here I'm fetching the data from the database mongodb using golang. Suppose I have an Id attribute and i want to receive the data on the basis of this id and it was easy by passing the id attribute in the query like below:-
c.Find(bson.M{"_id": 1}).One(&data)
If the id is given 1. but I have an case that i have find two or more at one time on the basis of the ids that it will returns the array of the ids like "_id":[1,2,3] then How will I retrieve the data from that ids. Can anyone help for if.
EDITED
IS this question solve my problem.
Thanks

How to accomplish WHERE IN query in Cloud Firestore [duplicate]

This question already has answers here:
Google Firestore - How to get several documents by multiple ids in one round-trip?
(17 answers)
Closed 5 years ago.
I have tried to figure out how to return a query based on whether the values are in an array I have client side. I so far have found nothing regarding the issue. Is this possible?
Firestore now supports "IN" queries:
Announcement
Documentation
Example:
let citiesRef = db.collection("cities")
citiesRef.whereField("country", in: ["USA", "Japan"])
Before November 2019
In Firestore, there is no "where in" like you might be used to with SQL.
If you know the values you want to query, perform different queries for each one, and call getDocument() on each of the DocumentReference objects. You typically would do this in a loop an collect the results yourself.