如何列出Cloud Firestore文档中的子集合 [英] How to list subcollections in a Cloud Firestore document
本文介绍了如何列出Cloud Firestore文档中的子集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我将此最小数据库存储在Cloud Firestore中。我怎样才能检索 subCollection1
和 subCollection2
的名称?
Say I have this minimal database stored in Cloud Firestore. How could I retrieve the names of subCollection1
and subCollection2
?
rootCollection {
aDocument: {
someField: { value: 1 },
anotherField: { value: 2 }
subCollection1: ...,
subCollection2: ...,
}
}
我希望能够只读取 aDocument
中的ID,但只有当我 get()$时出现的字段c $ c>该文件。
I would expect to be able to just read the ids off of aDocument
, but only the fields show up when I get()
the document.
rootRef.doc('aDocument').get()
.then(doc =>
// only logs [ "someField", "anotherField" ], no collections
console.log( Object.keys(doc.data()) )
)
推荐答案
在节点中.js你将在'ListCollectionIds'方法之后
In Node.js you'll be after the 'ListCollectionIds' method
var firestore = require('firestore.v1beta1');
var client = firestore.v1beta1({
// optional auth parameters.
});
// Iterate over all elements.
var formattedParent = client.anyPathPath("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
client.listCollectionIds({parent: formattedParent}).then(function(responses) {
var resources = responses[0];
for (var i = 0; i < resources.length; ++i) {
// doThingsWith(resources[i])
}
})
.catch(function(err) {
console.error(err);
});
客户端SDK(Web,iOS,Android)目前不支持此功能。
This is not currently supported in the client SDKs (Web, iOS, Android).
这篇关于如何列出Cloud Firestore文档中的子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文