问题
I have this query where I am trying to get a document from a sub-collection but it doesnt get anything, neither it shows any error:
const db = firebase.firestore(9;
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);
})
However, if I try to query only a document from the collection then it works:
let ref = db().collection('myCollection').doc('EzGNfNl63LQvjdauFWosG08Ishj2');
EDIT: Screenshot added
回答1:
Change this:
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);
})
Into this:
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() is a method and db is a constant.
来源:https://stackoverflow.com/questions/61147374/why-i-cant-query-sub-collection-or-a-document-from-a-sub-collection-in-firebase