Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用Python API了解Firestore中有哪些集合_Python 3.x_Firebase_Google Cloud Firestore - Fatal编程技术网

Python 3.x 如何使用Python API了解Firestore中有哪些集合

Python 3.x 如何使用Python API了解Firestore中有哪些集合,python-3.x,firebase,google-cloud-firestore,Python 3.x,Firebase,Google Cloud Firestore,我正在使用Python从客户端连接到firestore数据库 问题是我不知道如何查看他在数据库中的收藏: from google.cloud import firestore import firebase_admin from firebase_admin import credentials from firebase_admin import firestore cred = credentials.Certificate('credentials/credentials.json')

我正在使用Python从客户端连接到firestore数据库

问题是我不知道如何查看他在数据库中的收藏:

from google.cloud import firestore
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore


cred = credentials.Certificate('credentials/credentials.json')
app = firebase_admin.initialize_app(cred)

db = firestore.client()

users_ref = db.collection(u'name_of_colection')
docs = users_ref.stream()

for doc in docs:
    print(u'{} => {}'.format(doc.id, doc.to_dict()))
我一直在寻找如何获得他收藏的名称,但我没有发现任何对我有用的东西。我也试过:

cols = db.collections()
list_col = []
for col in cols:
    list_col.append(col)

len(list_col)
我得到了len=6

然后,我对生成的列表中的不同列执行了以下操作:

docs = list_col[5].stream()

data = []

for doc in docs:
    data.append(doc.to_dict())
print(data) 

这些数据打印了一个包含键和值的字典,但我不知道只能得到一个包含集合名称的列表,

您在fire base中看到的任何集合都取决于您的权限。 你可以用

query = client.collection_group('mygroup')
or 
query = client.collections()
它提供了顶级层次结构,您必须多次运行才能找到最低的文档级别

query = client.collection_group('mygroup')
@param {string} collectionId Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash. @returns {Query} The created Query.

collections()[source]
List top-level collections of the client’s database.

Returns
iterator of subcollections of the current document.

Return type
Sequence[CollectionReference]

您在fire base中看到的任何收藏都取决于您的权限。 你可以用

query = client.collection_group('mygroup')
or 
query = client.collections()
它提供了顶级层次结构,您必须多次运行才能找到最低的文档级别

query = client.collection_group('mygroup')
@param {string} collectionId Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash. @returns {Query} The created Query.

collections()[source]
List top-level collections of the client’s database.

Returns
iterator of subcollections of the current document.

Return type
Sequence[CollectionReference]

我认为您必须从每个集合中获取
id
(这是您正在谈论的
集合名称

list_col = []
for col in collections:
    list_col.append(col.id) // <-- add this please
print(list_col)
list_col=[]
对于集合中的col:

list_col.append(col.id)/我认为您必须从每个集合中获取
id
(这就是您所说的
集合名称

list_col = []
for col in collections:
    list_col.append(col.id) // <-- add this please
print(list_col)
list_col=[]
对于集合中的col:

list_col.append(col.id)//非常有用,谢谢。在当前的API文档中找不到。非常有用,谢谢。在当前的API文档中找不到。