Jack tileman
Jack tileman

Reputation: 871

Adding document and subcollection to a collection - firestore python

We have a collection in Google Firestore.

Can we add a document with data and a subcollection under this new document in one statement?

Upvotes: 0

Views: 273

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

In one statement, no. Strictly speaking, most programming languages are going to require at least one statement for each document to write using the provided APIs.

In one batch, yes. You can simply do a batch write to create any two documents simultaneously. Parent documents and subcollections do not need to exist in order to create a nested document, so there is not even any requirement to create the parent document, if that's what you were wondering.

Also, you can't create a subcollection that doesn't "exist". It will exist when the first document is written, and disappear when the last document is deleted.

Upvotes: 1

Related Questions