[SERVER-11097] Possible unanticipated conversion to regex Created: 09/Oct/13  Updated: 09/Jul/16  Resolved: 21/Oct/13

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kerem Kat Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Amazon mongo ubuntu package


Operating System: Linux
Participants:

 Description   

Mongo client throws the following error upon issueing a find command that contains the string /^10/s in xxxID field in at least one document.

Error: 16863 Error converting /^10/s in field xxxID to a JS RegExp object: SyntaxError: Invalid flags supplied to RegExp constructor 's'



 Comments   
Comment by Kerem Kat [ 21/Oct/13 ]

Hi Dan,

This error is thrown even when the query is just

db.f.find()

One of the document fields contains the expression

/^10/s

Comment by Daniel Pasette (Inactive) [ 21/Oct/13 ]

Hi Karem, this is a bug in the documentation, and I've opened a ticket for it.

Javascript only supports the 'g', 'i', and 'm' option natively. In order to use the options "s" and "x" from javascript, you need to use the following form:

> db.f.insert({x:"foo\nbar"})
> db.f.find({x: { $regex: /foo.*bar/}})                     // no 's' option specified returns nothing
> db.f.find({x: { $regex: /foo.*bar/, $options:'s'}})   // with 's', the document is returned
{ "_id" : ObjectId("5264a69e0a7c73e1ce43bf17"), "x" : "foo\nbar" }

Generated at Thu Feb 08 03:24:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.