I am trying to listen to documents in collection from Python code using example from Firestore Documentation. I receive correct data when listening root collection, but got nothing when listening subcollection. Here's my code:
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)
Subcollection exists in Firestore and non-empty. But in first case (1) I got non-empty lists of elements and changes (and updates), and in other case (2) just two empty lists (and nothing when update subcollection). As I know there are no differences in root/sub- collections, so, please, explain where am I wrong.
UPD: Similar code in node.js works fine, so looks like it is error in python client library.
node.js snippet:
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}`);
});