1

I have a nested collection/document Firestore DB:

/events/evtid/users/user
 Coll  Docs  Coll  Docs

I am trying to get the document ids from evtid documents using the below script:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

# Use a service account.
cred = credentials.Certificate('mycredentials.json')

app = firebase_admin.initialize_app(cred)

db = firestore.client()

coll = db.collection("events").stream()

for doc in coll:
    print(f'{doc.id}')

But nothing is presented. If I put an id for an especific document in evtid and the subcollection users ->

coll = db.collection("events").document("someid").collection("users").stream()

then it gets the documents (user). I don't know the ids for the documents in evtid and I first need to find them out.

What am I doing wrong?

A screenshot how the structure looks like enter image description here

BBR
  • 23
  • 4

1 Answers1

2

Based on what I can see in your Firestore database snapshot, apparently there are no documents in the events collection.

The reason for this is that the document IDs in that collection are in italics, which usually means that the main documents have been deleted, but the subcollections within them still exist. As a result, you can retrieve documents from the users subcollections, but not from the events collection.

The fact that you are able to see the deleted documents ids is because You just have users subcollection under document IDs, which causes the Firebase console to show the document IDs of the events collection, so that you can select them.

If you want to backfill that deleted data with new one without disturbing the users subcollection then you can use a collection group query on users subcollection, loop through those results, and write the parent document with something like

document.ref.parent.parent.set({ user: "Bob", age: 18 })

Reference :

Also check :

Rohit Kharche
  • 2,541
  • 1
  • 2
  • 13