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

Query Select Method is causing empty results

Open dmarshall83 opened this issue 3 years ago • 3 comments

I'm having an issue where when I use the select method on a query I get no results. I have a simple datastore holding user profile data under the Profile kind. The structure of an entity of that kind is as follows.

{
  id: string;
  name: string;
  email: string;
  picture: string;
  roles: string[];
  boards: string[];
  defaultBoard: string;
}

When I run a query getting all the users with a name falling in a specific character range I get the results that I expect and select only the fields I need I get no results.

const query = datastore
        .createQuery("Profile")
        .filter("name", ">=", "Da")
        .filter("name", "<=", "Daz")
        .select(["name", "email", "id", "picture"]);

const [entities] = await retry(() => query.run());

If I comment out the select it will work fine. I have the proper index built and have even tried to rebuild it but that did not help.

- kind: Profile
    properties:
      - name: name
      - name: email
      - name: id
      - name: picture 

Do you have any idea if I'm doing something wrong? I have used select in the past successfully but it appears not to be working now.

Thanks

Environment details

  • OS: Windows 10
  • Node.js version: v14.15.4
  • npm version: 6.14.10
  • @google-cloud/datastore version: ^6.3.1

Thanks!

dmarshall83 avatar Nov 01 '21 19:11 dmarshall83

Any follow up on this?

dmarshall83 avatar Jan 05 '22 16:01 dmarshall83

I hit the same issue yesterday.

vicb avatar Jan 05 '22 16:01 vicb

What is that retry function? Could you provide an import please?

danieljbruce avatar May 30 '22 18:05 danieljbruce

Can you try this?

// Imports the Google Cloud client library
const {Datastore} = require('@google-cloud/datastore');

// Creates a client
const datastore = new Datastore();

async function getResults() {
  const query = datastore
      .createQuery("Profile")
      .filter("name", ">=", "Da")
      .filter("name", "<=", "Daz")
      .select(["name", "email", "id", "picture"]);

  const [entities] = await query.run();
  console.log(entities);
}

getResults();

danieljbruce avatar Jan 31 '23 15:01 danieljbruce

Can't reproduce. Please open if you need more help.

danieljbruce avatar Feb 09 '23 20:02 danieljbruce