是否可以检查集合或子集合是否存在? [英] Is possible to check if a collection or sub collection exists?

查看:86
本文介绍了是否可以检查集合或子集合是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查firestore中是否存在用于nodejs的子集合?

Is there a way to check if a sub collection exists in firestore for nodejs?

当前我在文档中使用doc.exists,但是我需要检查文档中是否存在子类以便写入一些数据.

Currently I am using doc.exists for documents but I need to check if a subcolletion exists within a document in order to write some data or not.

推荐答案

是的.您可以使用docs.length来知道子集合是否存在.

Yes, there is. You can use docs.length to know if the subcollection exists.

我制作了一个样本来指导您,希望对您有所帮助.

I made a sample to guide you, hope it helps.

 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');
          }
        });
    }
  });

这篇关于是否可以检查集合或子集合是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆