我将firebase firestore用作我的React Native项目的后端数据库。 我需要从数据库中检索数据。如果代码如下所示,那么效果很好
unsubscribe = firebase.firestore().collection('messages').where('user', "==", this.props.user.uid).onSnapshot(this.onCollectionUpdate)
但是,如果“用户”字段是具有ID字段的对象,我如何检索数据?
答案 0 :(得分:0)
如果文档是使用类似以下对象的对象创建的:
var obj = {
user: {
id: '234567'
},
otherField: 'abcd'
};
,例如使用以下命令创建:
docRef.set(obj);
您可以按以下方式查询它:
firebase.firestore().collection('messages').where('user.id', "==", this.props.user.uid).onSnapshot(this.onCollectionUpdate)
答案 1 :(得分:0)
只需使用.doc('但是您的ID在这里'),而不是使用.where()。 所以您的情况是
.doc(obj.user.id).onSnap .....