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

190
Views
AND occasionally produces wrong result on shell and node native driver

I’ve built a dynamic query generator to create my desired queries based on many factors, however, in rare cases it acted weird. After a day on reading logs I found a situation that can be simplified in this:

db.users.find({att: ‘a’, att: ‘b’})

What I expect is that mongodb by default uses AND, so above query’s result should be an empty array. However, it’s not! But when I use AND explicitly, the result is an empty array

db.users.find({$and: [{att: 'a'}, {att: ‘b'}]})
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In javascript object’s keys should be unique, otherwise the value will be replaced by the latest value (also mongodb shell is based on js, so it follows some rules of js)

const t = {att: 'a', att: 'b'};
console.log(t);

So in your case your query is acting like this:

db.users.find({att: ‘b’})

You’ve to handle this situation on your code if you want the result be empty in the mentioned condition

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!