如何将具有自定义 ID 的文档添加到 Firestore [英] How to add Document with Custom ID to firestore
本文介绍了如何将具有自定义 ID 的文档添加到 Firestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有机会使用自定义生成的 id 而不是 Firestore 引擎生成的 id 将文档添加到 firestore 集合中?
解决方案
要使用自定义 ID,您需要使用 .set
,而不是 .add
这将创建一个 ID 为LA"的文档:
db.collection("cities").doc("LA").set({名称:洛杉矶",状态:CA",国家:美国"})
这取自官方文档此处>
Is there any chance to add a document to firestore collection with custom generated id, not the id generated by firestore engine?
解决方案
To use a custom ID you need to use .set
, rather than .add
This creates a document with the ID "LA":
db.collection("cities").doc("LA").set({
name: "Los Angeles",
state: "CA",
country: "USA"
})
This is taken from the official docs here
这篇关于如何将具有自定义 ID 的文档添加到 Firestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文