Firebase Product: Firestore
Describe the problem:
I couldn't find anywhere a way to select or find orphaned sub-collections, this is possible just manually using the web console.
This is in the works and we will update you as we get closer to releasing this.
Any update ?
@google-cloud/firestore v0.18.0 and above support traversing the full set of data in a Firestore database via DocumentReference.listCollections() and CollectionReference.listDocuments(). You should be able to get the newest version of this SDK if you update your dependency on firebase-admin.
@schmidt-sebastian how does this work since we don't have the ref?
@jimmykane I'm not sure what "ref" you are referring to. Can you elaborate on what you're trying to accomplish?
This is something I'm curious about as well, if we know we have a bunch of orphaned sub collections from older code that was not properly doing deletes, how can we purge that orphan data? We won't know the ref or path to those orphaned collections as they used to be subcollections of previously deleted documents
With listDocuments() and listCollections() you should be able to traverse and find any document in your Firestore hierarchy. Note that you might have to traverse your project's data from the root if you don't know where your orphaned documents are located.
is there a property we can check on a document to see if it's orphaned?
Since a document can be considered "orphaned" only when one of its parent documents does not exist, a way to do this would be to walk up the document hierarchy (via .parent) and call get() on every DocumentReference. You can then use DocumentSnapshot.exists to check whether there is a backing document in Firestore.
great suggestion, works for me 馃憤
Most helpful comment
@google-cloud/firestorev0.18.0 and above support traversing the full set of data in a Firestore database viaDocumentReference.listCollections()andCollectionReference.listDocuments(). You should be able to get the newest version of this SDK if you update your dependency onfirebase-admin.