我目前正在手动迭代firestore中的文档字段并将它们放入一个我将其字符串化为JSON的对象中。
有没有办法自动化这个过程?就像是:
var userEnrollments = ToJson(await admin.firestore().collection(USERS + "/" + x.uid + "/" + ENROLMENT));
DocumentSnapshot有一个方法data(),它将文档的全部内容(没有子集合)作为纯JavaScript对象返回。
admin.firestore().doc('path/to/doc').get().then(snapshot => {
const data = snapshot.data() // a plain JS object
})
尝试使用observable
var userEnrollments = Observable<User>;
Document userDoc = this.db.doc<User>('User/'+id);
this.userEnrollments = this.userDoc.valueChanges();
你可以使用像Observable<User[]>;
这样的数组:FirestoreCollection<User>;
我在角火中使用类似的东西。你也可以在firebase中使用ASYNC
。