Home > database >  Firestore setDoc() method somehow generates a unique identifier when doc says it won't
Firestore setDoc() method somehow generates a unique identifier when doc says it won't

Time:05-07

enter image description here

CodePudding user response:

If you don't specify document ID in doc(collctionRef) then it'll generate one automatically. The same was in previous SDK:

// This would add a Document with random ID

// V8
colRef.doc().set({})

// V9
setDoc(doc(colRef))

From the same documentation,

Behind the scenes, .add(...) and .doc().set(...) are completely equivalent, so you can use whichever is more convenient.

  • Related