简体   繁体   English

预期 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore

[英]Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

i have been solving this issue since past 2 days but cant get any idea of how it is solved自过去 2 天以来我一直在解决这个问题,但不知道它是如何解决的

const handleSignUp = () => {
    auth
    .createUserWithEmailAndPassword(email, password)
    .then(userCredentials => {
      console.log(userCredentials.user.uid)
      const user = userCredentials.user;
      console.log('Registered with:', user.email);
      
      setDoc(doc(db, "users", "LA"), {
        name: "Los Angeles",
        // state: "CA",
        // country: "USA"
      });

      })
      .catch(error => alert(error.message))
  }

The Firebase module is here if it need any changes of any dependency or any version please suggest as firebase version is 9.6.11,while firestore is of 3.4.14 Firebase 模块在这里如果它需要任何依赖项或任何版本的任何更改,请建议 firebase 版本是 9.6.11,而 firestore 是 3.4.14

// Import the functions you need from the SDKs you need
// import  firebase from "firebase";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
import "firebase/compat/database"
// import { getFirestore } from "@firebase/firestore";
import { getFirestore } from 'firebase/firestore'

// import { getFirestore } from 'firebase/firestore/lite'


const firebaseConfig = {
  apiKey: ........................
  authDomain: ........................
  projectId: ........................
  storageBucket: ........................
  messagingSenderId: ........................
  appId: ........................
};

// Initialize Firebase
let app;
if (firebase.apps.length === 0) {
  app = firebase.initializeApp(firebaseConfig);
} else {
  app = firebase.app()
}

export const auth = firebase.auth()
// export const db = firebase.firestore();
export const db = getFirestore(app)

The error indicates that you are calling setDoc() function to something that is not a DocumentReference or a CollectionReference.该错误表明您正在调用 setDoc() function 到不是 DocumentReference 或 CollectionReference 的东西。
You may try to get the details from the console log as to which variable reference it is hitting the above error and understand why what you are calling it on is not a valid CollectionReference or DocumentReference.您可以尝试从控制台日志中获取有关哪个变量引用遇到上述错误的详细信息,并了解为什么您调用它的不是有效的 CollectionReference 或 DocumentReference。 Please read through the helpful documentation for Collection Reference请通读收集参考的有用文档
The function setDoc(),writes to the document referred to by the specified DocumentReference. function setDoc() 写入指定 DocumentReference 引用的文档。 If the document does not yet exist, it will be created.如果该文档尚不存在,则会创建该文档。 If you provide merge or mergeFields, the provided data can be merged into an existing document.The result of this write will only be reflected in document reads that occur after the returned promise resolves.如果您提供merge或mergeFields,则可以将提供的数据合并到现有文档中。此写入的结果将仅反映在返回的promise解析后发生的文档读取中。 If the client is offline, the write fails.如果客户端离线,则写入失败。 If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.如果您想在客户端联机之前查看本地修改或缓冲区写入,请使用完整的 Firestore SDK。
Also check and verify that you are to call the firebase admin sdk rather than the client SDK and see if that works.还要检查并确认您要调用firebase 管理员 sdk而不是客户端 SDK 并查看是否有效。

It's an AngularFire version issue, basically if you're using Angular 12, with Firebase 9 you need @angular/fire@^7.0这是一个 AngularFire 版本问题,基本上如果你使用 Angular 12 和 Firebase 9 你需要 @angular/fire@^7.0

The compatibility table on the firebase page is key: https://github.com/angular/angularfire#angular-and-firebase-versions firebase 页面上的兼容性表是关键: https://github.com/angular/angularfire#angular-and-firebase-versions

I struggled with this issue for hours?days?我在这个问题上挣扎了几个小时?几天? and it was because I had angularfire 7.4 (even 7.2 didn't work).那是因为我有 angularfire 7.4(甚至 7.2 也没有用)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cloud Functions:collection() 的第一个参数应为 CollectionReference、DocumentReference 或 FirebaseFirestore - Cloud Functions: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore Firestore v9 预期 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore - Firestore v9 Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore 如何访问 firebase FirebaseError:预期 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore - How can I access firebase FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore 我该如何解决 FirebaseError:collection() 的预期第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore - How can i solve FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore 有人可以帮我吗 - FirebaseError:collection() 的第一个参数应该是 CollectionReference、DocumentReference 或 FirebaseFirestore? - Can someone help me - FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore? CollectionReference 到 DocumentReference - CollectionReference to DocumentReference 如何计算 flutter 中的 firebasefirestore 集合中的消息数 - How to count number of messages in firebasefirestore collection in flutter Angular Firestore:获取集合时 Map DocumentReference 属性为 object - Angular Firestore: Map DocumentReference attribute to object while fetching collection 在 Intents 中传递 FirebaseFirestore 引用 - Pass FirebaseFirestore reference in Intents 无法将数据发送到 FirebaseFirestore - Unable to send data to FirebaseFirestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM