Javascript 如何更新firestore子集合字段

Javascript 如何更新firestore子集合字段,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我试图更新firestore中的一个字段,但找不到正确的调用: changeAlertState(senderId, receiverId, alertType, bool){ let type = alertType == 'toBe' ? 'toBeAlerted' : 'toAlert'; this.afs.firestore .collection("books") .doc(senderId + '/' + receiverId) .update({

我试图
更新firestore中的一个字段,但找不到正确的调用:

changeAlertState(senderId, receiverId, alertType, bool){

  let type = alertType == 'toBe' ? 'toBeAlerted' : 'toAlert';

  this.afs.firestore
  .collection("books")
  .doc(senderId + '/' + receiverId)
  .update({
                        [type]: bool
                    })
  .then(() => {
                console.log("Contact " + receiverId + " alert successfully updated!");
            });
}
下面是数据库:

我得到这个错误:

FirebaseError:[代码=无效参数]:无效的文档引用。文档引用的段数必须为偶数,但books/33KlbrBypXMe888vpO7dXgDVrfY2/HLH7AO7IABZBUKEPPGFK1I8LQ1RX1的段数为3


基本上,数据库结构必须是集合、文档、集合、文档等

这是:

文档存在于集合中,集合只是文档的容器

集合包含文档而不包含其他内容。它不能直接包含带值的原始字段,也不能包含其他集合


如果你能分享更多关于你想要的结构的信息(例如一个更完整的屏幕截图),这会有所帮助。如何转换为正确嵌套的集合/文档设置也可能有所帮助。

您正在将部分字段路径传递到对
doc()
的调用中。这不起作用,因为您需要(仅)将文档ID传递到
doc
。然后,通过使用

var value = {};
value[receiverId+"."+type] = bool;
this.afs.firestore
  .collection("books")
  .doc(senderId)
  .update(value)
另请参阅