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

相關問題