如何将具有自定义ID的文档添加到firestore(Angular) [英] How to add Document with Custom ID to firestore (Angular)

查看:90
本文介绍了如何将具有自定义ID的文档添加到firestore(Angular)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有机会使用自定义生成的id将文档添加到firestore集合,而不是firestore引擎生成的id。

Is there any chance to add a document to firestore collection with custom generated id, not the id generated by firestore engine.

提前感谢您的回复。

推荐答案

要使用自定义ID,您需要使用 .set ,而不是比 .add

To use a custom ID you need to use .set, rather than .add

这会创建一个ID为LA的文档:

This creates a document with the ID "LA":

db.collection("cities").doc("LA").set({
    name: "Los Angeles",
    state: "CA",
    country: "USA"
})

这取自官方文档此处

这篇关于如何将具有自定义ID的文档添加到firestore(Angular)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆