Skip to content

Datastore: field types of array are always showing indexed regardless of excludeFromIndexes #2615

@DaveyEdwards

Description

@DaveyEdwards

Saving array's shows it is indexed (not all the actual items in the array, just the field), even when excludeFromIndexes: true.

I am not sure if this is normal behavior and the whole array is not actually stored in the index. I had asked this originally in gstore-node issues and he said to ask here :)

You can see the "circles" field shows indexed

image

Inside the "circles" it is showing all array items are excluded from index

image

Environment details

  • OS: Windows 10
  • Node.js version: 6.11.2
  • npm version: 3.10.10
  • google-cloud-node version:
    Replecated on google-cloud: 0.56.0
    and @google-cloud/datastore: 1.1.0
    I originally was using gstore-node and saw this problem, and now I am using just raw datastore and still have it.

Steps to reproduce

Seed database with a field of array

My test function

createEntity([
  {
    name: 'kind',
    value: 'Pages',
    excludeFromIndexes: true,
  },
  {
    name: '_id',
    value: '6',
  },
  {
    name: 'title',
    value: 'my first title',
  },
  {
    name: 'dateCreated',
    value: new Date(),
  },
  {
    name: 'string',
    value: 'A long string goes here',
    excludeFromIndexes: true,
  },
  {
    name: 'circles',
    value: ['1', '2', '3', '4'],
    excludeFromIndexes: true,
  },
]);

The actual save function

export default async function createEntity(entity) {
  let response = null;
  let kind = null;
  let dsKey = null;

  try {
    entity.map((entityFeilds) => {
      if (entityFeilds.name === '_id') {
        dsKey = entityFeilds.value;
        if (dsKey === '') {
          dsKey = null;
        }
        return dsKey;
      }
      if (entityFeilds.name === 'kind') {
        kind = entityFeilds.value;
        return kind;
      }
      return null;
    });
    const key = datastoreClient.key([kind, dsKey]);
    const data = entity;
    const newEntity = {
      key,
      data,
    };

    response = await datastoreClient.save(newEntity);
  } catch (err) {
    console.error('save err', err);
  }
  return response;
}

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions