I am trying to create a new document without any data (any fields) in it. But I can't find a way.
I am trying to create a new document without any data (any fields) in it. But I can't find a way.
There is no way you can create a document without any data. You can use the following lines of code:
let db = Firestore.firestore()
let docRef = db.collection("yourCollection").document("yourDocument")
let documentID = docRef.documentID
But this should give you only the id of the document. Please note that it doesn't mean that it will create a document for you. With other words, it merely "reserves" an id for a document in a particular collection. So for a document to actualy exist, you should add at least a property of any type. It can even hold a null value. In fact, why to have a document if it doesn't hold anything?
However, if you want to create a subcollection within a document, you can use a document that actually does not exist. It will be displayed in italic, as explained in my answer from the following post:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With