0

I haven't been able to find an answer in any online documentation. Wondering if it's possible to add a new document with a sub-collection in a single operation?

Below is the code I have, it seems to work - but is the correct way to add a sub-collection or are batched writes the only way?

reference?.addDocument(data: ["foo" : "bar"]).collection("path").addDocument(data: ["foo2" : "bar2"], completion: { (error) in
    // handle write here
)}
emrepun
  • 2,496
  • 2
  • 15
  • 33
enc_life
  • 4,973
  • 1
  • 15
  • 27

1 Answers1

1

If you're asking if it's OK to create a document without a prior collection or subcollection, that's not a problem. In fact, there is no other way for a collection or subcollection to exist. You simply must create a document in order for that collection to exist. It will cease to exist when the last document is deleted. They are not like filesystem folders that can exist with no files in them.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441