【问题标题】:Creating key in firestore在 Firestore 中创建密钥
【发布时间】:2019-04-28 02:13:43
【问题描述】:

我想在 Firestore 的集合中设置实际值之前生成一个密钥。在 firebase 中,语法类似于 firebase.database().ref().child('myposts').push().key

如何在firestore 中做到这一点。

【问题讨论】:

  • 嗨,@raju,它有效吗?如果是这样,您可以将答案标记为正确吗?谢谢

标签: javascript angular firebase google-cloud-firestore


【解决方案1】:

我用...

构造函数(私有 afs:AngularFirestore){}

pushkey = this.afs.createId()

那你就可以了

this.afs.collection("你的收藏").doc(this.pushkey).add({id:this.pushkey, name: "chris"})

【讨论】:

【解决方案2】:

在 Firestore 中,您可以调用add() 生成随机密钥来推送数据。

javascript 中的示例

db.collection('pathRef').add({
 ...
}).then(function(docRef) {
 ...
});

Documentation

【讨论】:

  • 嗨,我正在使用 Javascript/Angular。
  • 嗨,有没有可能做这样的事情 const randKey = firestore.collection(myposts/raju).add({});
  • 是的,你可以这样做const randKey = db.collection('/myposts/raju').add({
  • 不允许使用 myposts/raju
  • 在引用中使用 ' ' 并记住使用/myposts/raju
猜你喜欢
  • 1970-01-01
  • 2018-11-26
  • 2016-12-11
  • 2020-09-29
  • 1970-01-01
  • 2017-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多