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

Support retrieving and editing excludeFromIndexes (parity with other client libraries)

Open calsmith opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. There is no way to get/set which fields of an entity are indexed after initial entity creation.

Use case:

  1. Retrieve an entity
  2. Add a new field to the entity
  3. Exclude the new field from being indexed

Unlike the other client libraries, there is no way to achieve this with Node JS.

Describe the solution you'd like Here's example code from the PHP Datastore library which easily enables this use case:

$ds = Datastore::get();
$entity = $ds->lookup($ds->key(...));
$entity["newField"] = 123;
$unindexedFields = $entity->excludedProperties(); // Get the unindexed fields.
$unindexedFields[] = "newField"; // Prevent the new field from being indexed.
$entity->setExcludeFromIndexes($unindexedFields);
$ds->update($entity);

Describe alternatives you've considered Without this functionality, we cannot use Node JS or this library for our project.

Additional context Related requests from other customers: https://github.com/googleapis/nodejs-datastore/issues/914 https://github.com/googleapis/nodejs-datastore/issues/935

calsmith avatar May 22 '23 14:05 calsmith

To support this feature we should write code to create and delete indexes. The following link shows this is not supported yet.

https://github.com/googleapis/nodejs-datastore/blob/cd59c718ebe6711603b08b3ba2677e5a984bc7e3/src/index-class.ts#L150-L151

danieljbruce avatar May 23 '23 20:05 danieljbruce

I have encountered the same problem as described in the issue #914 I tried to use datastore.merge to add a single property to the entity, but because the excludeFromIndexes resets to all properties indexed and because i have a very large string (in java it was Text) stored, i get an error. So what i have to do, is merge, but provide a full list of excludeFromIndexes so the merge works as expected. Is there any timeline for this to get fixed?

bogdan-nourescu avatar Jun 19 '24 14:06 bogdan-nourescu