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

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

问题描述

是否有机会使用自定义生成的ID(而不是Firestore引擎生成的ID)将文档添加到Firestore集合中?

解决方案

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

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

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

这摘自官方文档此处

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屋!

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