Reputation: 273
How to get document by id in google firestore? is there some get()
method? because I searched but didn't find a proper answer that suits to me :(
Update: this.itemscollection.doc(id).get()
didn't worked for me
Upvotes: 19
Views: 24731
Reputation: 6900
Try this code
this.itemscollection.doc(id).ref.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
Upvotes: 29
Reputation: 1246
the key to success working with angular 2( when using the package angularFire2 ) with firestore is to know that all the firestore methods in their official documention that manipulate single doc like 'get' 'set' 'update' are child of the 'ref' method Example insted
firestore - this.itemscollection.doc(id).get()
angularfirestore2 - this.itemscollection.doc(id).ref.get()
-------------------------------------
firestore - this.itemscollection.doc(id).set()
angularfirestore2 - this.itemscollection.doc(id).ref.set()
Upvotes: 7