0

enter image description here This is how my data look like.

I'm able to use FieldValue.increment(1) to update individual fields but is there a way to use FieldValue.increment(1) for specific individual elements in the array? Thanks in advance!

I tried using the following code:

firestore.collection('test').doc('I1raMaJArb1sWXWqQErE')
          .update({
        'rating.0': FieldValue.increment(1),
      });

But the whole rating became empty as seen enter image description here

2
  • Can you please provide your code snippets for better understanding? Commented Jun 16, 2021 at 15:04
  • ok I've just added the code Commented Jun 16, 2021 at 15:24

1 Answer 1

1

You can't use FieldValue.increment() if the field is part of the array. The value of the field inside the array is fixed. The best way to update or edit the field that part of an array is to read the entire document, modify the data in memory and update the field back into the document.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, got it. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.