Angular:
"@angular/core": "^5.2.1",
Firebase:
CloudFirestore
AngularFire:
angularfire2 : "^5.0.0-rc.6"
Issue
I am unable to get a document reference with an auto generated id. Base on the cloudFirestore documentation it should be possible to do the following.
var newCityRef = db.collection('cities').doc();
// Later...
var setDoc = newCityRef.set({
// ...
});
Currently, the the angularfire2 collection's doc() function has a mandatory parameter hence calling angularFirestore.collection('cities').doc() results in a typescript error.
Is this something the team is aware of? Are there plans to fix it?
Thanks
P.S
I know I can do collection angularFirestore.collection('cities').set({...}) which would auto generate a document id. However, I am trying to do a batch job which requires a document ref and my document is not pre-existing. Example
const batch = angularFirestore.firestore.batch();
const articleDocRef = angularFirestore.collection('articles').doc();
const journalistDocRef = angularFirestore.collection('journalist').doc('mike');
batch.set(articleDocRef, {'title': 'amazing article'});
batch.update(journalistDocRef, {'totalArticles': 200});
batch.commit()
In order for the above to work I have to get a docRef with an auto generated ID which is currently not possible.
Use AngularFirestore's createId() method for this.
thanks
Use AngularFirestore's
createId()method for this.
Ok but how do we use the createId() method?
Can you share an example?
Most helpful comment
Use AngularFirestore's
createId()method for this.