当文档说它不会时,Firestore setDoc() 方法会以某种方式生成一个唯一标识符
Firestore setDoc() method somehow generates a unique identifier when doc says it won't
When you use set() to create a document, you must specify an ID
但是,我刚刚了解到我可以在不指定ID的情况下调用setDoc
,它仍然会生成一个唯一标识符。
await setDoc(doc(collctionRef), {
createdAt: new Date(),
updatedAt: new Date(),
});
问题
- Firebase 文档是否已过时?还是我错过了什么?
- 如果这是真的,
addDoc
现在似乎没用了。或者它还有其他用途吗?
如果您没有在 doc(collctionRef)
中指定文档 ID,那么它会自动生成一个。之前的SDK也一样:
// This would add a Document with random ID
// V8
colRef.doc().set({})
// V9
setDoc(doc(colRef))
来自同一文档,
Behind the scenes, .add(...)
and .doc().set(...)
are completely equivalent, so you can use whichever is more convenient.
When you use set() to create a document, you must specify an ID
但是,我刚刚了解到我可以在不指定ID的情况下调用setDoc
,它仍然会生成一个唯一标识符。
await setDoc(doc(collctionRef), {
createdAt: new Date(),
updatedAt: new Date(),
});
问题
- Firebase 文档是否已过时?还是我错过了什么?
- 如果这是真的,
addDoc
现在似乎没用了。或者它还有其他用途吗?
如果您没有在 doc(collctionRef)
中指定文档 ID,那么它会自动生成一个。之前的SDK也一样:
// This would add a Document with random ID
// V8
colRef.doc().set({})
// V9
setDoc(doc(colRef))
来自同一文档,
Behind the scenes,
.add(...)
and.doc().set(...)
are completely equivalent, so you can use whichever is more convenient.