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

158
Vistas
Why is the result an empty array?

I use mongodb for my project.

when I put in this code - db.find( {"N": {$eq:1} } ) , the result is a empty array.

but when I put this code - db.find({$where : function(){return(this.N==1)}}), the result is the array that I want.

I think two codes are same. why is the result of first code an empty array?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The value is not a number as you claim, the syntax == is different than the strict eq operator === ( which is the equivalent~ of Mongo's $eq ) as can be seen in this example

1 == `1`

> true

While the strict operator

1 === '1'

> false

So you just need to change the code to match the string '1', like so:

db.find( {"N": {$eq:'1'} } 

Or if you want to support both cases:

db.find( {"N": {$in: [1, '1']} } 

I recommend you fix your schema and db to make sure it's aligned to what you believe the structure should be.

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