how to update firebase document field angular

Solutions on MaxInterview for how to update firebase document field angular by the best coders in the world

showing results for - "how to update firebase document field angular"
Santiago
26 May 2019
1// how to create a collection
2tutorials: Observable<any[]>;
3// db: AngularFireStore
4this.tutorials = db.collection('tutorials').valueChanges();
5
6// To get meta data and create collection
7tutorials: Observable<any[]>;
8this.tutorials = db.collection('tutorials').snapshotChanges();
9
10// how to add document to collection
11const tutorialsRef = db.collection('tutorials');
12const tutorial = { title: 'zkoder Tutorial', url: 'bezkoder.com/zkoder-tutorial' };
13tutorialsRef.add({ ...tutorial });
14
15// how to update a collection
16const tutorialsRef = db.collection('tutorials');
17tutorialsRef.doc('id').update({ title: 'zkoder new Tut#1' });
18
19// how to delete a document in a collection
20const tutorialsRef = db.collection('tutorials');
21tutorialsRef.doc('id').delete();
22
Fynn
10 Mar 2018
1updateDoc(_id: string, _value: string) {
2  let doc = this.afs.collection('options', ref => ref.where('id', '==', _id));
3  doc.snapshotChanges().pipe(
4    map(actions => actions.map(a => {                                                      
5      const data = a.payload.doc.data();
6      const id = a.payload.doc.id;
7      return { id, ...data };
8    }))).subscribe((_doc: any) => {
9     let id = _doc[0].payload.doc.id; //first result of query [0]
10     this.afs.doc(`options/${id}`).update({rating: _value});
11    })
12}
13