I'm using Angular and Firestore
What I want to do
Iterate over a
FirestorecollectionChange the value of a field in each
AngularFirestoreDocumentwithin that collection
This is where I grab my minutes collection
export class MinutesComponent {
minutesArray: AngularFirestoreCollection<any>;
minutes: Observable<any[]>;
constructor(private afs: AngularFirestore) {
this.minutesArray = afs.collection<any>('minutes', ref => ref.orderBy('year', 'desc'));
this.minutes = this.minutesArray.valueChanges();
...
}
}
In my constructor, this is how I try to update each document
this.minutes.subscribe(minutes => {
minutes.forEach(minute => {
####RETRIEVES INDIVIDUAL DOCUMENT FROM DATABASE
const minuteRef = this.afs.doc(`minutes/${minute.id}`);
if (minute.month === 'January') {
minuteRef.update({'month': 1 });
} else if (minute.month === 'jan') {
minuteRef.update({'month': 1 });
} else {
minuteRef.update({'month': 2 });
}
});
Thoughts? I want to loop through the document collection and update a field value of each document in the collection.
For example, if
document.month = january
I would like to change this to
document.month = 1
Thanks.