最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Get Firestore document as plain Javascript object? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 8

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 
})

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.

发布评论

评论列表(0)

  1. 暂无评论