grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

Allow using custom masks to update nested fields #147

Closed zhezhang77 closed 2 years ago

zhezhang77 commented 2 years ago

Fix #146 Unable to update nested fields with custome mask in updateDocument()

The user can choose update a nested field with mask like

['field3.field4']
Or update a field with '.' (dot) in its name with mask quoted by ` like
['`field3.field4`']

zhezhang77 commented 2 years ago

Remove bracketed '`' to support syntax update(docPath, {'nested.path': updatedValue}, true). In the Web version v8 API, it is also the developer's responsibility to escape the field if he wants to update a filed which name contains dot.

firebase
  .collection("users")
  .doc(`${authUser}`)
  .update({
    [`Questions.Q11.${name}`]: { //<-- Update field 'Questions.Q11.XXXX'
      text: name,
      amount: Number(value),
      EF: Number(ef),
    },
  });
abkarino commented 2 years ago

I think the latest update wouldn't work since you are escaping the backquote, so developer can't really add them.

zhezhang77 commented 2 years ago

I think the latest update wouldn't work since you are escaping the backquote, so developer can't really add them.

Seems to need to fix the behaviour of 'Document.wrapMap()' at first. I will close the PR and then submit another one later.