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

489
Views
error in mongo DB query - $cond operator

This is BSON document. I want only those entries whose attribute length is greater than zero

/* 1 */
    {
        "_id" : "http://exhentai.org",
        "length" : 0,
        "value" : ""
    }

    /* 2 */
    {
        "_id" : "http://vuclip.com",
        "length" : 77,
        "value" : "vuclip scroll learn official weve launched close news team pressroom linkedin"
    }

    /* 3 */
    {
        "_id" : "http://hbogo.com",
        "length" : 174,
        "value" : "hbo hbo anywhere hbo enjoy instant unlimited access every episode every season best hbo shows movies comedy sports documentaries hbo free subscription participating providers"
    }

So output should be

       /* 2 */
        {
            "_id" : "http://vuclip.com",
            "length" : 77,
            "value" : "vuclip scroll learn official weve launched close news team pressroom linkedin"
        }

        /* 3 */
        {
            "_id" : "http://hbogo.com",
            "length" : 174,
            "value" : "hbo hbo anywhere hbo enjoy instant unlimited access every episode every season best hbo shows movies comedy sports documentaries hbo free subscription participating providers"
        }

What I tried

db.coll.aggregate([
    {$project: { 
       Text:
               {
                 $cond: { if: { $gte: [ "$length", 20 ] }, then: "$value" }
               }
       _id : 0
     }}
])
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This can be simply done using $gt Operator

db.collection.find({'length':{ $gt:0 }})
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!