Reputation: 22916
I'm currently manually itearting over document fields in firestore and putting them into an object which I stringify to JSON.
Is there a way to automate the process? Something like:
var userEnrollments = ToJson(await admin.firestore().collection(USERS + "/" + x.uid + "/" + ENROLMENT));
Upvotes: 5
Views: 5565
Reputation: 317372
DocumentSnapshot has a method data() that returns the entire contents (without subcollections) of the document as a plain JavaScript object.
admin.firestore().doc('path/to/doc').get().then(snapshot => {
const data = snapshot.data() // a plain JS object
})
Upvotes: 8
Reputation: 6007
Try use observable
var userEnrollments = Observable<User>;
Document userDoc = this.db.doc<User>('User/'+id);
this.userEnrollments = this.userDoc.valueChanges();
You can use array like: Observable<User[]>;
with FirestoreCollection<User>;
I use similar in angular fire.
You can use ASYNC
in firebase too.
Upvotes: 0