【发布时间】:2019-12-11 16:10:14
【问题描述】:
标题说明了一切,当我尝试使用代码通过 id 从 firestore 获取文档时:
firestore.collection('my_collection').get('foo')
.then(snapshot => {
snapshot.forEach(doc => {
const data = doc.data();
console.log(doc.id, data);
});
})
.catch(err => {
console.log('Error getting documents', err);
});
它抛出了这个错误:
FirebaseError: FirebaseError: Function Query.get() requires its first argument to be of type object, but it was: "foo"
所以我提供了一个带有 id 的对象:{id: "foo"}
这给了我另一个错误:
FirebaseError: FirebaseError: Unknown option 'id' passed to function Query.get(). Available options: source
如何通过 id 从集合中获取文档?
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore