当用户的 id 与文档 uid 匹配时,如何 return 来自 Firebase 的数组
How to return an array from Firebase when a user's id matches the document uid
我想知道如何使用查询从 Firebase 检索数组或 urls,检查当前用户的 id 是否与文档 uid 匹配,如果匹配,它 returns url 个字符串数组,如下图所示。
使用angularfire2你可以做如下操作:
this.itemDoc = afs.doc<any>('/lists/432jk....'); //You know the "the current user's id", then you can build the document ref (i.e. path)
this.item = this.itemDoc.valueChanges();
this.item.subscribe(value => {
const urlsArray = value.urls;
});
文档中的更多详细信息:https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md
或者您可以使用本机 JavaScript SDK,如下所示:
var docRef = db.collection('lists').doc('/lists/432jk....');
docRef.get().then(function(doc) {
if (doc.exists) {
const urlsArray = doc.data().urls;
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
我想知道如何使用查询从 Firebase 检索数组或 urls,检查当前用户的 id 是否与文档 uid 匹配,如果匹配,它 returns url 个字符串数组,如下图所示。
使用angularfire2你可以做如下操作:
this.itemDoc = afs.doc<any>('/lists/432jk....'); //You know the "the current user's id", then you can build the document ref (i.e. path)
this.item = this.itemDoc.valueChanges();
this.item.subscribe(value => {
const urlsArray = value.urls;
});
文档中的更多详细信息:https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md
或者您可以使用本机 JavaScript SDK,如下所示:
var docRef = db.collection('lists').doc('/lists/432jk....');
docRef.get().then(function(doc) {
if (doc.exists) {
const urlsArray = doc.data().urls;
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});