Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

393
Views
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 answers
Answer question

0

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

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

Try it here

over 4 years ago · Santiago Trujillo Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!