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

242
Vistas
How to use a mix of literals and variables in a MongoDB query

I'm currently trying to query a collection using a mix of literals and variables. For some reason the result comes back as null when I do this.

const result = await db.getCollection('myCollection').findOne({
  'someDate.someId': line['someId'],
});

// returns 'null'

However, if use a either both variables or both literals, it works just fine:

const key = 'someDate.someId'
const result = await db.getCollection('myCollection').findOne({
  key: line['oldId'],    // or 'key:value' could be both literals
});

// returns the result I am looking for

Why can I not do what I am trying to do in the first example? It's somewhat inconvenient to have to create a variable for the query - is there a way I achieve what I want without doing this?

about 4 years ago · Juan Pablo Isaza
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