node-firestore-import-export
node-firestore-import-export copied to clipboard
Nonexisiting parents should not be created after export/import
Context: Firestore has a concept of "non-exisitng" nodes in path
For example "collection/nonexsitingdoc/subcollection/doc1" It's possible to create a doc1 where "nonexsitingdoc" will not existing - in such case firestore UI in browser shows it as greyed out.
Expected behavior
Library doesn't create "nonexsisting" docs after export/import
Actual behavior
Library creates docs that are "nonexsisting" after export/import
Steps to reproduce the behavior
- Create a doc under the following path without creating intermediate docs/collections: "collection/nonexsitingdoc/subcollection/doc1"
- Export the whole collection
- Clean up database
- Import it back
My usecase
I have a collection of client with the counter in production like this:
Clients: users/{userId}/clients
Client counter: users/{userId}/clients/-counter-doc-/-conter-col-/counter
Both -counter-doc- and -conter-col- don't exisit in the database which is expected
But after exporting and importing to the dev project (for debug and troubleshooting) the lib creates both -counter-doc- and -conter-col-
Now when I fetch client list it also returns -conter-col- document as a client which breaks the internal logic.
Why need to keep that orphan child collection? This lib handles the "nonexsisting" document as an empty document. In JSON file, I believe there is no way to distinguish an empty parent document and a "nonexsisting" parent document.
@cuong0993 ok got you, firebase does distinguish them somehow thoughm, specifically in their admin UI.
I guess it should be possible to store a flag inside of that empty json and then skip creation of such docs/collections on import.
As to why, I've described my use case above, I basically store counter for the number of clients inside of the clients collection.
Maybe you can change this line to check if documentData is empty the skip set document (all empty documents will be not existed) https://github.com/cuong0993/node-firestore-import-export/blob/7b98376476b3b70eb0609577e837342dec2a24ef/src/lib/import.ts#L89
@cuong0993 thanks bro! I'll give it a try