Python Firestore:侦听子集合中的文档
我正在尝试使用来自的示例来听Python代码集合中的文档。我在侦听根集合时收到正确的数据,但在侦听子集合时未收到任何数据。 这是我的密码:Python Firestore:侦听子集合中的文档,python,google-cloud-firestore,google-cloud-python,Python,Google Cloud Firestore,Google Cloud Python,我正在尝试使用来自的示例来听Python代码集合中的文档。我在侦听根集合时收到正确的数据,但在侦听子集合时未收到任何数据。 这是我的密码: db = firestore.client() # Create a callback on_snapshot function to capture changes def on_snapshot(col_snapshot, changes, read_time): print(col_snapshot, type(col_snapshot))
db = firestore.client()
# Create a callback on_snapshot function to capture changes
def on_snapshot(col_snapshot, changes, read_time):
print(col_snapshot, type(col_snapshot))
print(changes, type(col_snapshot))
root_collection = u'shared-streams'
subcollection = u'shared-streams/eFC4T~lLyT/messages'
# Watch the root collection query (1)
col_query = db.collection(root_collection)
query_watch = col_query.on_snapshot(on_snapshot)
# Watch the subcollection query (2)
col_query = db.collection(subcollection)
query_watch = col_query.on_snapshot(on_snapshot)
子集合存在于Firestore中且不为空。但在第一种情况下(1)我得到了元素和更改(以及更新)的非空列表,而在另一种情况下(2)只有两个空列表(更新子集合时没有)。正如我所知,在根/子集合中没有区别,所以,请解释一下我错在哪里
UPD:node.js中类似的代码工作正常,所以看起来这是python客户端库中的错误
node.js代码段:
var db = admin.firestore();
var query = db.collection('shared-streams/eFC4T~lLyT/messages')
var observer = query.onSnapshot(querySnapshot => {
console.log(`Received query snapshot of size ${querySnapshot.size}`);
// ...
}, err => {
console.log(`Encountered error: ${err}`);
});