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

408
Vistas
Mongodb query to check if a particular field is not null ( aggregation)

I have queries like

{
"title": "sjncx",
"desciption": "cknxk jckd",
"price": "29.99",
"stock": "3",
...
}

I need to filter data if the title is not empty.( title exists and not null). And also is empty like ~ title: "" ~ ( so title exists but empty)

I tried for is not empty:

{'title': {'$ne': 'null'}}

I tried for is empty:

{'title': {'$type': 10}}

That doesn't work. What would be the reason?

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

0

You can use $in to cover both cases empty and null :

{
  "title": {
    "$nin": [null, ""]
  }
}

Try it here

over 4 years ago · Santiago Trujillo Denunciar

0

Use $and which is very expressive

db.collection.find({
  "$and": [
    {
      "title": {
        "$ne": null
      }
    },
    {
      "title": {
        "$ne": ""
      }
    }
  ]
})

You will just set your condition there. The doc

See: https://mongoplayground.net/p/V13mnmf6xGE

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