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));
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));
Share
Improve this question
edited Jan 2, 2018 at 2:42
meds
asked Jan 2, 2018 at 2:30
medsmeds
23k42 gold badges171 silver badges337 bronze badges
2 Answers
Reset to default 8DocumentSnapshot 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
})
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.