Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:14:59+00:00 2026-05-31T14:14:59+00:00

How will MongoDB evaluate this query: db.testCol.find( { $or : [ {a:1, b:12}, {b:9,

  • 0

How will MongoDB evaluate this query:

db.testCol.find(
{
    "$or" : [ {a:1, b:12}, {b:9, c:15}, {c:10, d:"foo"} ]
});

When scanning values in a document if first OR statement is TRUE will the other statements be also be evaluated?

Logically if the MongoDB is optimized other values in OR statement should not be evaluated, but I don’t know how MongoDB is implemented.

UPDATE:
I updated my query because it was wrong and it didn’t explain correctly what I was trying to accomplish. I need to find a set of documents that have different properties and if an exact combination of these properties is found the document must be returned.

The SQL equivalent of my query would be:

SELECT * FROM testCol 
WHERE (a = 1 AND b = 12) OR (b = 9 AND c = 15) OR (c = 10 AND d = 'foo'); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:15:00+00:00Added an answer on May 31, 2026 at 2:15 pm

    MongoDB will execute each clause of the $or operation as a seperate query and remove duplicates as a post processing pass. As such each clause can use a seperate index which is often very useful.

    In other words, it will NOT look at 1 document, see which of the OR clauses apply and do an early-out if the first clause is a match. Rather it does a full dataset query per clause and de-dupe after the fact. This may seem less than efficient but in practice it’s almost always faster since the first approach would only be able to hit at most one index for all clauses which is rarely efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Will a query like this on a recordset work rs.open select * from table
I've created a MongoDB aggregation query that will give me the sum of data
I need to provide a way that my mongodb server will store each document
Will limiting a query to one result record, improve performance in a large(ish) MySQL
I am writing a Maintenance Script for MongoDB that will compact collections from a
In MongoDB, what's the most efficient approach to sort an array in a document
By default MongoDB creates index on _id key in document. But when I ensure
Supposedly ReportsAnywhere will talk with MongoDB to generate reports. I am not sure if
This is from MongoDB docs : db.factories.insert( { name: xyz, metro: { city: New
In MongoDB I have a collection of documents called 'clients', where each document is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.