Dercni
Dercni

Reputation: 1224

Firestore update multiple records

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

Answers (1)

Doug Stevenson
Doug Stevenson

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

Related Questions