Reputation: 1224
I have a collection of documents that I wish to update following this:
https://firebase.google.com/docs/firestore/manage-data/add-data
I wish to increment a field in each doc by a value of two.
const collection = db.collection('groups').where('age', '> 20', right).get()
.then(response => {
response.docs.forEach((doc) => {
let updateGroup = doc.update(
{
days: doc.days + 2;
}
);
})
})
When I run the code above I receive the following error: TypeError: doc.update is not a function
Upvotes: 0
Views: 179
Reputation: 317948
Your doc
variable is not a DocumentReference. It's a DocumentSnapshot. You can see from the API documentation that it doesn't have an update()
method. If you want the DocumentReference from a snapshot, use its ref
property.
doc.ref.update(...)
Upvotes: 2