【问题标题】:Generating random Key firestore生成随机密钥火库
【发布时间】:2018-09-10 17:18:12
【问题描述】:
【问题讨论】:
标签:
javascript
firebase
key
google-cloud-firestore
【解决方案1】:
firestore uid 生成器非常容易使用:
const uid = admin.firestore().collection("tmp").doc().id
这样就可以解决问题而无需保存一些数据
但在您的具体示例中:如果您不指定任何密钥,它将由 firestore 自动生成:
await admin.firestore().collection("MY COLLECTION").doc().set(data)
【解决方案2】:
看起来您可以只使用 .add 方法,而不是自己自动生成 uuid。
https://firebase.google.com/docs/firestore/manage-data/add-data
// Add a new document with a generated id.
db.collection("cities").add({
name: "Tokyo",
country: "Japan"
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});