1

在JavaScript中,我写了这样的东西,但它返回错误>“文档引用必须有偶数段”。我需要使用“设置”而不是“添加”我的情况。如何在Firebase的Cloud Firestore中添加这样的数据?

const ref= db.collection("product"); 
ref.doc("111").doc("category").set({ clothes: true }); 

在Firebase的实时数据库中,我可以编写这样的代码,但在Firestore中我不能。

ref.child("111").child("category").set({ clothes: true }); 

如何在Firestore中编写这样的代码?

谢谢。

回答

2

这里的问题似乎是,您正尝试在文档中使用doc。这不是Firestore的设计。该集合可以具有文档和文档可以具有这个示例的集合。

var messageRef = db.collection('product').doc('productNumbers') 
      .collection('11111').doc('category'); 

您必须稍微改变您的数据结构以符合设计。这是一个reference

相关问题