Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Cloud Firestore找不到自定义文档id_Javascript_Google Cloud Firestore - Fatal编程技术网

Javascript Cloud Firestore找不到自定义文档id

Javascript Cloud Firestore找不到自定义文档id,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,如果我尝试获取自定义文档id,则此函数返回false 只有在firebase控制台上输入文档id时,才会返回true checkDot() { this.db.firestore.collection(this.DOT).doc(this.DOT).get() .then( doc => { console.log('Data is ', doc.exists); if (doc.exists) { // this.isDotEx

如果我尝试获取自定义文档id,则此函数返回false

只有在firebase控制台上输入文档id时,才会返回true

checkDot() {
     this.db.firestore.collection(this.DOT).doc(this.DOT).get()
     .then( doc => {
      console.log('Data is ', doc.exists);
      if (doc.exists)  {
       // this.isDotExist = true;
      console.log(doc, 'Colection exists');
    } 
else {
      // new Account Create
     console.log('Colection doos not exist');
     this.presentConfirm();
    }
     });

此函数将用户输入存储在数据库中

  async createNewAccount() {

  // Binding data from user input
  const { Company, Fname, Email, Password } =  this;
  try {
    // creating user account 
    const res = await this.afAuth.auth.createUserWithEmailAndPassword(Email, Password).then(cred => {
     // DOT value passed by another page, others from user input 
      this.db.collection(this.DOT).doc(this.DOT).collection(Company).doc(Fname).set({ Name: Fname });

    });
    this.showAlert('Succes', 'You have successfully registered!');
    this.route.navigate(['']);
    console.log(res);
  } catch (err) {
    this.showAlert('Error', err.message);
    // console.dir(err);
  }
}

正如您可以从社区中查看此问题一样,有一种特殊的方法可以通过documentId使用查询。方法是:“FieldPath.documentId()”

另一个参考是官方文档,您可以在其中找到以下代码示例,可以将其用作通过ID返回文档的起点

db.collection("collection").where("document", "==", true)
    .get()
        .then(function(querySnapshot) {
            querySnapshot.forEach(function(doc) {
               // doc.data() is never undefined for query doc snapshots
               console.log(doc.id, " => ", doc.data());
            });
        })
    .catch(function(error) {
    console.log("Error getting documents: ", error);
});
除此之外,下面还有一个来自社区的问题,提供了更多信息和示例,与您的类似问题相关,可能会对您有所帮助

如果这些信息对你有帮助,请告诉我