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

211
Views
using $gte and $lt for picking different rages of a specific field value

I'm trying to pick documents with cost fields between 0 and 5 then trying to pick documents with cost ranges between 10 and 15. For this, I'm using MongoDB aggregation

    const something = await dummyModel.aggregate([
      {
        $match: {
          fieldA: {
            $in: arryOfIds,
          },
          cost: {
            $or: [
              { $gte: 0, $lt: 5 },
              { $gte: 10, $lt: 15 },
            ],
          },
        },
      },
    ]);

With the above approach, I'm getting this error from mongoose.

"message": "unknown operator: $or",

Any Idea on this to pick ranges in MongoDB using mongoose

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should do it with find query.

db.collection.find({
  "fieldA": {
    "$in": arryOfIds,
  },
  "$or": [
    {
      "cost": {
        "$gte": 0,
        "$lt": 5
      }
    },
    {
      "cost": {
        "$gte": 10,
        "$lt": 15
      }
    }
  ]
})

Working example

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!