Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save ID to Firestore document

I'd like to save the id of my document as a property as well, not only as a reference on the collection. At the moment I save it like this:

const newSet: AngularFirestoreDocument<SetModel> = this.AngularFirestore.doc('users/' + this.navParams.data.userId);

    // adding user to our ddbb
    newSet.collection('sets').add(this.set)
      .then(function (docRef) {
        // ok
      })
      .catch(function (error) {
        // error
      });

Would be that possible? Or do I need to save it, get the id and update it again?

PS this is my ddbb structure: enter image description here

enter image description here

like image 485
Dani Avatar asked Jan 16 '18 15:01

Dani


1 Answers

1 - create a const id. 2 - set id in object. 3 - save

  createEvent(set){
    const id = this.firestore.createId();
    set.id = id;
    return this.firestore.doc(`users/${id}`).set(ev);
  }
like image 146
Elialber Lopes Avatar answered Oct 22 '22 02:10

Elialber Lopes