jloosli / node-firestore-import-export

Firestore data import and export
https://www.npmjs.com/package/node-firestore-import-export
MIT License
392 stars 79 forks source link

Support document ID generation by firestore #81

Open themikejr opened 5 years ago

themikejr commented 5 years ago

Please correct me if I'm wrong, but as far as I can tell, this library does not currently offer the option to allow firestore to generate ID for documents in collection or subcollections, rather the ID has to be specified upfront in the data that is being imported.

If this is currently not supported, I suggest a feature where a token like <docId> can be inserted into JSON that is being imported, and the library will then delegate to firestore to generate an ID for that document.

If I've missed an existing feature please let me know. Otherwise, let's discuss how this should work.

damjanprvc commented 5 years ago

Same missing feature found (which limits the use - for my needs) and same thought. It would be great if this could be added.

jloosli commented 5 years ago

Good idea! How would you propose the formatting for multiple documents to be generated? Something like the following?

{
  "<docId>-1": {
    "name": "Susan",
    "age": 22
  }, 
  "<docId>-2": {
    "name": "Lilly",
    "age": 42
  }
}

Any other suggestions for a token? I'm also wondering about something like __docId__*** since the double under (__) is used elsewhere as a token.

damjanprvc commented 5 years ago

__docId__ seems for me the best for a token. There is no need to number each id, since they get auto-generated using the .doc() Method without any parameters. https://firebase.google.com/docs/firestore/manage-data/add-data#add_a_document

jloosli commented 4 years ago

The dilemma is that using the same __docId__ for each key is invalid json....it would need to be unique in some way...

kontinuity commented 4 years ago

A good example implementation is here https://www.npmjs.com/package/firestore-export-import#import-data-to-firestore-auto-generate-document-id

The idea is to have the JSON be an array (not an object at the top level). e.g.

{
  "<docId>-1": {
    "name": "Susan",
    "age": 22
  }, 
  "<docId>-2": {
    "name": "Lilly",
    "age": 42
  }
}

Becomes:

[
  {
    "name": "Susan",
    "age": 22
  }, 
  {
    "name": "Lilly",
    "age": 42
  }
]

Feedback @jloosli @damjanprvc?

roselily8 commented 3 years ago

Hi, is this feature added?