Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonexisiting parents should not be created after export/import #869

Open
arthabus opened this issue Sep 18, 2023 · 4 comments
Open

Nonexisiting parents should not be created after export/import #869

arthabus opened this issue Sep 18, 2023 · 4 comments

Comments

@arthabus
Copy link

arthabus commented Sep 18, 2023

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

  1. Create a doc under the following path without creating intermediate docs/collections:
    "collection/nonexsitingdoc/subcollection/doc1"
  2. Export the whole collection
  3. Clean up database
  4. 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.

@cuong0993
Copy link

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.

@arthabus
Copy link
Author

arthabus commented Sep 18, 2023

@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.

@cuong0993
Copy link

cuong0993 commented Sep 18, 2023

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

@arthabus
Copy link
Author

@cuong0993 thanks bro! I'll give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants