Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
How to retrieve entities by passing array of IDs as input in Google datastore?

I am trying to implement the following SQL logic in the datastore,

SELECT * from table where id in [1,2,3,4,5]

Implementing this in datastore, I want to retrieve all the corresponding entities with these IDs as an array.

let employees = []
try {
  for (let id of idArray) {
    const employee = await employeeRepo.getOneById(workspace, id)
    employees.push(employee)
  }
} catch (e) {
  throw e;
 }

This is the naive logic of the function, and I am trying to reduce it to a single query.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Are you using the Node.js library referenced here: https://cloud.google.com/datastore/docs/reference/libraries

There is a function get where you can pass in an array of keys and it will return the array of entities.

https://googleapis.dev/nodejs/datastore/latest/Datastore.html#get

over 4 years ago · Santiago Trujillo Denunciar

0

It's possible to do by using get as mentioned in the documentation

Here's an example of how to do it based on your code:

const employee1 = this.datastore.key(['Employee', 1]);
const employee2 = this.datastore.key(['Employee', 2]);
const employee3 = this.datastore.key(['Employee', 3]);

const keys = [employee1, employee2, employee3];

try {
    const [employees] = await datastore.get(keys);
} catch (e) {
    throw e;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda