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

  • SEARCH
  • Home
  • 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 7941349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:38:41+00:00 2026-06-03T23:38:41+00:00

–> Please see updates at the bottom, I have replicated the same issue in

  • 0

–>Please see updates at the bottom, I have replicated the same issue in Mongo shell

My criteria is being passed via GET parameters and gets placed into $data (as an assc array).
Then it gets to below section, where each search term becomes partial not exact match. After that we remove (unset) empty criterias.

In total there are possible 15 fields which at least 1 and at most all 15 can be set.

foreach ($data as $k => $v) { 
     // Make them partial match
     $data[$k] = new MongoRegex('/'.$v.'/i');
     // Remove empty criteria
     if (empty($v)) unset($data[$k]); 
}
// Run the search
$cursor = $this->collection->find($data);

Everything works sweet as long as passed criterias are 4 or less like:

Array ( 
   [phone] => MongoRegex Object ( [regex] => 433 [flags] => i ) 
   [property_name] => MongoRegex Object ( [regex] => west [flags] => i ) 
   [city] => MongoRegex Object ( [regex] => H [flags] => i ) 
   [zip_postcode] => MongoRegex Object ( [regex] => 9 [flags] => i ) 
)

This returns 5 results.

But any criteria added after 4th one are ineffective.

Array ( 
   [phone] => MongoRegex Object ( [regex] => 433 [flags] => i ) 
   [state_province] => MongoRegex Object ( [regex] => Virginia [flags] => i ) 
   [property_name] => MongoRegex Object ( [regex] => west [flags] => i ) 
   [city] => MongoRegex Object ( [regex] => H [flags] => i ) 
   [zip_postcode] => MongoRegex Object ( [regex] => 9 [flags] => i )
)

This should return 2 but still returns 5 and it will return 5 no matter how many criteria items are added

— Update —

So I have tried it in the Shell and to my surprise it also does not work there.

db.property_list.find({phone:/433/, property_name:/west/, city:/h/, zip_postcode:/9/}).count()

returns 5

Now when I add the 5th parameter it should narrow down the results to 2 but it is ineffective and still show count as 5!!!

db.property_list.find({phone:/433/, property_name:/west/, city:/h/, zip_postcode:/9/, state_province:/Virginia/}).count()

returns 5

With a lot of experiments, I realized it is only the first 4 criteria being picked up!! Like if in the last example I switch the place for 'state_province' and 'city' it will be ‘city’ criteria which will be ineffective as it will be the 5th criteria!!

— New Update —

It turns out if I use normal match instead of regex on the 5th criteria it will work. Am I correct to assume Mongo can do find() only for 4 regex criteria?
So this will correctly returns 1

db.property_list.find({phone:/433/, property_name:/west/, city:/h/, zip_postcode:/9/, state_province:Virginia}).count()
  • 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-06-03T23:38:43+00:00Added an answer on June 3, 2026 at 11:38 pm

    There is a hard limit of 4 allowed regex criteria per query. It was fixed in the core mongo code about six months ago: https://github.com/mongodb/mongo/commit/62554d064a264f9b6c28099ba71421f250bbbba9

    It looks like this fix has not been pulled into the 1.8 or 2.0 branches of mongo yet, here’s the v1.8 branch showing the hard limit: https://github.com/mongodb/mongo/blob/v1.8/db/matcher.cpp#L159

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

Sidebar

Related Questions

So to start, I have an array of XML files. These files need to
Have a webpage that will be viewed by mainly IE users, so CSS3 is
i have a text file with the following data: Calculated Concentrations 30.55 73.48 298.25
I have a simple restful service that transforms a JAXB-anntotated beans to response XML
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We have different types of hyphens/dashes (in some text) populated in db. Before comparing
I have a PHP application that stores PHP datetime to my MySQL table. I
I'm struggling to position the second level of a dropdown nav menu and was

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.