Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create Firestore Bundles in Node.js?

As per suggestion on Firebase documentation on Firestore bundles, I haven’t found the best way to create bundle based on the example given above. I don’t know what I have to include in docSnapshot. I know what I have to fill in collection. But what is the case if CollectionGroup? There is no detail explanation about it, either. Can someone from Firebase team explain what I have to include in docSnapshot? I have collection "Music_Epic", for example?

  const bundleId = "latest-Epic";
  const bundle = firestore.bundle(bundleId);
  const docSnapshot = await firestore.doc("Music_Epic/").get(); //What should be here?
  const querySnapshot = await firestore.collection("Music_Epic").get();

  // Build the bundle
  // Note how querySnapshot is named "latest-stories-query"
  const bundleBuffer = bundle.add(docSnapshot); // Add a document
  bundleBuffer.add("latest-Epic-query", querySnapshot); // Add a named query.
  bundleBuffer.build();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The add() takes either a DocumentSnapshot or (queryName, QuerySnapshot) as parameters. Collection Groups queries also return a QuerySnapshot so you can follow the same method used for querying a single collection.

const bundle = firestore.bundle();
const querySnapshot = await firestore.collection("Music_Epic").get();

// For collectionGroup queries:
// const querySnapshot = await firestore.collectionGroup("col_name").get();

const bundleBuffer = bundle.add('latest_music_epic_query', querySnapshot);
bundleBuffer.build();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading