相关疑难解决方法(0)

如何列出Cloud Firestore文档中的子集合

假设我将此最小数据库存储在Cloud Firestore中.我怎么能检索的名字subCollection1subCollection2

rootCollection {
    aDocument: {
        someField: { value: 1 },
        anotherField: { value: 2 }
        subCollection1: ...,
        subCollection2: ...,
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望能够只读取ID aDocument,但只有字段出现在我get()的文档中.

rootRef.doc('aDocument').get()
  .then(doc =>

    // only logs [ "someField", "anotherField" ], no collections
    console.log( Object.keys(doc.data()) )
  )
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-firestore

9
推荐指数
2
解决办法
3626
查看次数

为什么 ref.getCollections() 不被识别为函数?

我正在做一个将用户数据存储在 cloud firestore 上的网站。我使用它一次获取用户文档的所有子集合:

db.collection('users').doc(userID).getCollections().then( collections => {
  /*I get my collections and I enjoy it :D*/
})
Run Code Online (Sandbox Code Playgroud)

问题是无法识别此功能。我在控制台上找到了这条消息:

TypeError: db.collection(...).doc(...).getCollections is not a function
Run Code Online (Sandbox Code Playgroud)

我知道否则我可以获得所有子集,但由于配额有限,我想保存最大的读数。所有其他 firebase 函数都在我的项目中工作(如get()set())并且getCollections()在文档中。感谢您的帮助 !

javascript node.js firebase reactjs

4
推荐指数
1
解决办法
2004
查看次数

在一次读取计数中仅获取来自 Cloud Firestore 的集合 ID

在Cloud Foreshore 的这份文档中提到,“请求一个集合 ID 列表,您需要为读取一个文档付费”。

现在我在我的项目中使用 AngularFire 和 Ionic3。我的要求是仅从具有 where 条件的集合中获取集合 ID。如果我执行以下操作,结果中的读取次数 = 文档数。

let snap = this.afs.collection('path').ref
        .where('field', "==",'data').get();

snap.forEach(x => {
          list.push(x.id);
        });
Run Code Online (Sandbox Code Playgroud)

我无法使用getCollections()我在几个地方找到的方法作为解决方案。

如果您有解决方案,请告诉我。

firebase angularfire ionic-framework google-cloud-firestore

4
推荐指数
2
解决办法
2882
查看次数