Firebase cloud store provides "get" method to retrieve the entire collection as following -
db.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc);
});
});
I am using Angularfire2 version 5.0.0rc3 in my ionic 3 project to connect with firebase cloud storage.
I am trying to access this get method as following -
constructor(
private afs: AngularFirestore
) {
this.afs.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc);
});
});
}
But here, "get" method is not working. Can anyone tell me who to use this 'get' method with firebase clould storage and angularfire2.
js admin clients have listCollections() on Firestore to get that list. Or, if you're looking for subcollections nested under a document, use DocumentReference. listCollections(). If you want to get a list on any platform, you should maintain that list yourself in a known collection inside a known document id.
A collection contains documents and nothing else. It can't directly contain raw fields with values, and it can't contain other collections. (See Hierarchical Data for an explanation of how to structure more complex data in Cloud Firestore.)
Actually, it works, just call firestore this.afs.firestore.collection
let userDoc = this.afs.firestore.collection(`users`);
userDoc.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>", doc.data());
})
})
Not exist get()
method in the AngularFirestore collection
, use subscribe
instead.
Here is an example:
this.afs.collection("users").snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
}).subscribe((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc);
});
});
I recommend you to read angularfire2 guide first.
I am also facing same issue. for me the browser hangs when large data is getting retrieved. Moreover valueChanges() listens for new changes and the piece of code starts execution again.
For retrieving large data, its better to write a cloud function. Get the data from the cloud function and then display that under Angular application.
Firebase Cloud Functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With