how to add document to angular fire code example
Example 1: how to update firebase document field angular
tutorials: Observable<any[]>;
this.tutorials = db.collection('tutorials').valueChanges();
tutorials: Observable<any[]>;
this.tutorials = db.collection('tutorials').snapshotChanges();
const tutorialsRef = db.collection('tutorials');
const tutorial = { title: 'zkoder Tutorial', url: 'bezkoder.com/zkoder-tutorial' };
tutorialsRef.add({ ...tutorial });
const tutorialsRef = db.collection('tutorials');
tutorialsRef.doc('id').update({ title: 'zkoder new Tut#1' });
const tutorialsRef = db.collection('tutorials');
tutorialsRef.doc('id').delete();
Example 2: how to update firebase document field angular
updateDoc(_id: string, _value: string) {
let doc = this.afs.collection('options', ref => ref.where('id', '==', _id));
doc.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
}))).subscribe((_doc: any) => {
let id = _doc[0].payload.doc.id;
this.afs.doc(`options/${id}`).update({rating: _value});
})
}