有没有一种方法来检查是否存在一个子集合在firestore中为nodejs?可以检查一个集合或子集合是否存在?
目前我正在使用doc.exists
作为文档,但我需要检查子文档是否存在于文档中以编写一些数据。
有没有一种方法来检查是否存在一个子集合在firestore中为nodejs?可以检查一个集合或子集合是否存在?
目前我正在使用doc.exists
作为文档,但我需要检查子文档是否存在于文档中以编写一些数据。
是的,有。您可以使用docs.length来了解子集合是否存在。
我做了一个样本来指导你,希望它有帮助。
this.db.collection('users').doc('uid')
.get().then(
doc => {
if (doc.exists) {
this.db.collection('users').doc('uid').collection('friendsSubcollection').get().
then(sub => {
if (sub.docs.length > 0) {
console.log('subcollection exists');
}
});
}
});
这个答案真的帮我反正:) – Ahsath
很好的答案!谢谢! – JeffMinsungKim
我发现另一个答案,为了这个伟大工程,是在这里https://stackoverflow.com/questions/46880323/how-to-check-if-a-cloud-firestore-document-exists-when-using -realtime更新。这也适用于这里描述的子集合https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/559 –