0

This function is returning false if i try to get the custom document id.

It is only returning true when I enter document id on the firebase console.

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();
    }
     });

This function stores user input in the database

  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);
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

As you can check in this question from the Community Query Firebase Firestore documents by the ID, there is a special method that you can use query via documentId. The method is this: 'FieldPath.documentId()'

Another reference is the official documentation Execute Query, where you can find the following example of code that you can use as a start point, to return documents via 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);
});

Besides that, there is the below question from the Community with more information and examples, related to a similar to yours, that might help you.

Let me know if the information helped you!

rsalinas
  • 1,507
  • 8
  • 9