Why does this RegExp query return all results?

Viewed 91

I have a MongoDB 3.2 server. My collection contains documents like the following:

{
    "name": "string",
    "explicitMods": [
        "+48 to Blah",
        "-13% to Blah",
        "12 to 18 to Blah"
    ]
}

If I write this:

myCollection.find({ "explicitMods": /bad string/ })

I get zero results, as expected.

However if I write this:

myCollection.find({ "explicitMods": /\d+ to \d+/ })

I get all documents in the collection. This is unexpected because I actually want documents containing substrings like 12 to 18. If I change the regexp to /\d+ to \d+z/ it correctly matches nothing.

1 Answers
Related