Querying MongoDB with a regular expression exceeding 32764 characters in length silently fails without returning any results or raising any errors.
An example of this behaviour is as follows.
Create a document in the mongo shell:
> String.prototype.repeat = function(n) { return new Array(n + 1).join(this) } function (n) { return (new Array(n + 1)).join(this); } > db.example.insert({ field : "x".repeat(50000) })
Querying for the document with a 32764 character regular expression will return a result as expected:
> db.example.find({ field : { $regex : "x".repeat(32764) }}) > { "_id" : ObjectId("4f9e1678d3eff3503675d2be"), "field" : "..." }
Querying for a document with a 32765 character regular expression fails with no errors nor results:
> db.example.find({ field : { $regex : "x".repeat(32765) }})
>
As per Eliot on the mongodb-user list:
"That looks like the default pcre max size.
Can you open a ticket @ jira.mongodb.org to see if its possible to
increase the size?"