Firestore在控制台创建集合或添加文档时不工作

37 阅读1分钟

我试图在控制台中创建一个Firestore的集合,但它不允许我继续前进。它要求添加第一个文件,但保存按钮仍被禁用,即使我添加了一个带有Auth-ID的ID,你可以在下面的图片中看到。

我在网上看了很多对话,他们都说我们需要设置一个ID,但对我来说似乎没有什么作用。

另一方面,我试着按照文档中的例子从我的ReactJS应用中直接添加一个新的文档,但同样的事情发生在这里,没有错误,但什么也没有发生。

import { collection, addDoc } from "firebase/firestore"; 

try {
   const docRef = await addDoc(collection(db, "users"), {
       first: "Ada",
       last: "Lovelace",
       born: 1815
   });
      console.log("Document written with ID: ", docRef.id);
 } catch (e) {
      console.error("Error adding document: ", e);
}

在上面的代码中,docRef.id是undefined ,没有任何东西被添加到集合中。控制台打印的内容如下:

Document written with ID:  undefined

我的规则被设置为 "生产",如下所示:

  `rules_version = '2';
   service cloud.firestore {
       match /databases/{database}/documents {
       match /{document=**} {
       allow read, write: if false;
      }
    }
   }`

文档中说,Cloud Firestore creates collections and documents implicitly the first time you add data to the document. 所以它应该在那里,谢谢帮助。