nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

How to modify entity preserving indexed/unindexed properties?

Open vladimirkiva opened this issue 3 years ago • 1 comments

Getting the provided sample code for nodejs:

  • I'm trying to modify only one property ('done') of the entity Task in sample code tasks.markdone.js
  • What code you've already tried: tasks.add.js and tasks.markdone.js
  • Any error messages you're getting: no

I'm expecting the code in tasks.markdone.js should modify only one property -- done. But it actually modifies two properties: done (as expected) and description. Initially, description property in not indexed as it is created in tasks.add.js. But tasks.markdone.js makes it indexed, that is not expected and undesired.

For this particular case it's easy to fix:

transaction.save({
    key: taskKey,
    data: task,
    excludeFromIndexes: [
        "description"
    ]
});

But in real life fields that are excluded from indexes might be dynamic, so

The question is: What is the best way to get an entity preserving all it's indexed/unindexed fields, modify just one field and save it in the way not to change not touched indexes?

vladimirkiva avatar Jan 22 '22 04:01 vladimirkiva

Can you confirm that the code you are using is https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.add.js and https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.markdone.js? Or are you using a tutorial on cloud.google.com? They should be the same but sometimes end up out of sync so trying to understand where the issue might be coming from.

meredithslota avatar Aug 29 '22 16:08 meredithslota

Related request: https://github.com/googleapis/nodejs-datastore/issues/1111

calsmith avatar May 22 '23 14:05 calsmith

Closing in favor of #1111.

meredithslota avatar Nov 20 '23 20:11 meredithslota