0

I have a data structure that looks as follows: enter image description here

This is the top level of the collection: enter image description here

I want to write to increment the field count but I can't do it. I've tried so many different methods that I'd rather not go through all of them. The closest I've gotten was through:

const pageRef = admin.firestore().collection("pages").doc(image.page);

pageRef.set(
  {
    [`images.${image.position}.count`]: admin.firestore.FieldValue.increment(
      1
    ),
  },
  { merge: true }
);

But that leaves me with: enter image description here

Please help. Changing the structure of pages is an option.

This is what I've tried to replicate: Update fields in nested objects in firestore documents?

1 Answer 1

1

The issue is on how the point notaition is being used.

In the Post you shared the example they use is:

var setAda = dbFirestore.collection('users').doc('alovelace').update({
    "first.test": "12345"
});

Applying this to your Code and model would be:

const pageRef = admin.firestore().collection("pages").doc(image.page);

pageRef.set(
  {
    `images[${image.position}].count`: admin.firestore.FieldValue.increment(
      1
    ),
  },
  { merge: true }
);

This will affect the element in the Array Images, the element image.position its value count.

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

Comments

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.