【问题标题】:Firestore push to subcollection with batch.setFirestore 使用 batch.set 推送到子集合
【发布时间】:2023-04-03 19:48:01
【问题描述】:

所以我在这里想要实现的是这样的数据结构:

id: "BgaI9c5gHB666MpwXPqb"
name: "Rhys Clay"
"pushkey1" : true,
"pushkey2" : true

正如您在上面看到的,我想将文档中的按键存储为平面对象。

这是我目前的代码:

let contactsRef: DocumentReference = this.afs.doc(`contacts/${contactId}`).ref;
batch.set(contactsRef, {
  'name'      : contact.name,
  'number'    : contact.number,
  'nativeId'  : contact.nativeId,
  'id'        : contactId,
  groupdId    : true
});

batch.commit();

]

但是这样我会得到类似的东西:

id: "BgaI9c5gHB666MpwXPqb"
name: "Rhys Clay"
groupdId : true,

任何帮助表示赞赏。

【问题讨论】:

  • 我现在实际上认为最好将其存储为平面对象。更新我的代码

标签: angular firebase google-cloud-firestore angularfire2


【解决方案1】:

所以我想通了,如果将变量名保存为键,请将括号括起来:

[groupId]     : 'true'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多