0

I would like such a data structure:

enter image description here

I tried this:

  this.db
      .collection("users")
      .doc(`${this.id}`)
      .update({
        records: [
          {
            index: pointIndex,
            x: pointX,
            y: pointY
          },
        ],
      });

But this solution does not put records[1], records[2], etc... in the database. Just generates an array and always updates its values.

enter image description here

How can I do the data structure shown in the first image to have records[1], records[2] etc ....?

1
  • This is because record has only one element. Commented Mar 23, 2021 at 1:13

1 Answer 1

1

Use the FieldValue.arrayUnion to add your new data, example:

this.db
    .collection('users')
    .doc(`${this.id}`)
    .update({
      records: firebase.firestore.FieldValue.arrayUnion(
              {
                index: pointIndex,
                x: pointX,
                y: pointY
              }
             )
    });
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.