Get Document Id When Searching With Where Clause Firestore
I want to be able to get the document id of a document that I have just queried with a where clause in firestore. Here is an example that I have at the moment: db.collection('Users
Solution 1:
an example solution to what you're looking for can be found in the Firestore documentation:
db.collection("cities").where("capital", "==", true)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshotsconsole.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
You can simply call doc.id
to retrieve the document's ID.
Source: https://cloud.google.com/firestore/docs/query-data/get-data
Post a Comment for "Get Document Id When Searching With Where Clause Firestore"