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

1.6K
Views
Mongodb Query giving error: Expression $gt takes exactly 2 arguments. 1 were passed in

I am writting the following query to retrive the records based on 2 conditions.Executing the Query giving me error:

> db.employee.find({age:{$lt:32}},{salary:{$lt:40000}})

Here is the error Message:

Error: error: {
        "ok" : 0,
        "errmsg" : "Expression $lt takes exactly 2 arguments. 1 were passed in.",
        "code" : 16020,
        "codeName" : "Location16020"
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

To do a find query based in two conditions, you need to do in the same query object.

Note that you are doing:

find({obj1},{obj2}

But second parameter into find method is for projection (docs)

So you need this query:

db.collection.find({
  "age": {
    "$lt": 32
  },
  "salary": {
    "$lt": 40000
  }
})

Note how there is only one object with two fields: age and salary.
Something like find( { age:{}, salary:{}} ).

Example here

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!