Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3150

Allow retrieving PCRE-style regexes in documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0.0, 3.6.10
    • Affects Version/s: 4.0.0, 3.6.4
    • Component/s: None
    • 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)
      

            Assignee:
            andy.mina@mongodb.com Andy Mina
            Reporter:
            michael.rose@mongodb.com Michael Rose (Inactive)
            Durran Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: