-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 4.0.0, 3.6.4
-
Component/s: None
-
Empty show more show less
-
Not Needed
Problem Description
The issue occurs when a document is stored in a collection with a field being a BSONRegex that was created in a non-JavaScript environment with non-JavaScript supported format.
This error happens with driver version 4.x - did not test with 3.x.
You can use the following example to insert a document into a collection with a Ruby regular expression:
require 'mongo' Mongo::Logger.logger.level = Logger::DEBUG client = Mongo::Client.new('mongodb://127.0.0.1/test') collection = client[:testcoll] puts collection.insert_one( { rubyprogramtestRegexWihtM: /(?-i)AA_/im } )
Note: Make sure to run gem install mongo --user-install before.
Then run the following NodeJS script:
const MongoClient = require('mongodb').MongoClient; (async() => { const client = await MongoClient.connect('mongodb://127.0.0.1/'); console.log('Connected...') const db = client.db('test'); const coll = db.collection('testcoll'); const docs = await coll.find().toArray(); console.log(docs); client.close(); })().catch(e => process.nextTick(() => {throw e;}));
Expected Result
The document is displayed properly.
Actual Result
An error is thrown:
SyntaxError: Invalid regular expression: /(?-i)AA_/: Invalid group at new RegExp (<anonymous>) at deserializeObject (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/parser/deserializer.js:348:28) at deserializeObject (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/parser/deserializer.js:167:32) at deserializeObject (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/parser/deserializer.js:188:28) at deserializeObject (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/parser/deserializer.js:167:32) at Object.deserialize (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/parser/deserializer.js:49:12) at Object.deserialize (/Users/michael.rose/Software/mongodb/mongosh/node_modules/bson/lib/bson.js:155:27) at BinMsg.parse (/Users/michael.rose/Software/mongodb/mongosh/node_modules/mongodb/lib/cmap/commands.js:586:54) at MessageStream.messageHandler (/Users/michael.rose/Software/mongodb/mongosh/node_modules/mongodb/lib/cmap/connection.js:402:21)
- is depended on by
-
MONGOSH-623 Retrieving stored PCRE-style regex causes the shell to throw
- Closed