我在此查询中尝试从子集合中获取文档,但未获取任何内容,也未显示任何错误。可能是Firebase方面的问题,还是我在这里做错了什么?
const db = firebase.firestore();
let ref = db.collection('myCollection').doc('EzGNfNl63LQvjdauFWosG08Ishj2').collection('privat').doc('privat');
ref.get()
.then(doc => { //it doesnt continue to next line, just executes this one
if (doc.exists) {
console.log("Doc exists:", doc.data())
}else{
console.log("Doc deostn exists:")
}
}).catch(error => {
console.log('Error getting restaurant data: ', error);
})
但是,如果我尝试仅查询集合中的文档,那么它将起作用:
let ref = db().collection('myCollection').doc('EzGNfNl63LQvjdauFWosG08Ishj2');
答案 0 :(得分:0)
更改此:
const db = firebase.firestore.
let ref = db().collection('myCollection').doc('EzGNfNl63LQvjdauFWosG08Ishj2').collection('privat').doc('privat');
ref.get()
.then(doc => { //it doesnt continue to next line, just executes this one
if (doc.exists) {
console.log("Doc exists:", doc.data())
}else{
console.log("Doc deostn exists:")
}
}).catch(error => {
console.log('Error getting restaurant data: ', error);
})
对此:
const db = firebase.firestore();
let ref = db.collection('myCollection').doc('EzGNfNl63LQvjdauFWosG08Ishj2').collection('privat').doc('privat');
ref.get()
.then(doc => { //it doesnt continue to next line, just executes this one
if (doc.exists) {
console.log("Doc exists:", doc.data())
}else{
console.log("Doc deostn exists:")
}
}).catch(error => {
console.log('Error getting restaurant data: ', error);
})
firestore()
是一个方法,而db
是一个常量。