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

Investigate NODE-4455 - Error when using regex to get the collections for an Atlas connection

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Not Needed

      NODE-4455 Description

      What problem are you facing?

      Getting the below error from listCollections function when trying to fetch the collections from an Atlas connection. This is not happening for other mongo connections.
       
       

      const mongoClient = require('mongodb').MongoClient; 
      const url = 'mongodb+srv://vidya:vidya%402219@cluster0.ea8nbt4.mongodb.net'; //'mongodb://localhost:27017' 
      
      console.log(`> Connecting to mongoDB @ ${url}`); mongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }) .then(client => { if (!client) { console.log('> Failed to connect mongoDB - no client'); } else { console.log('> Connected'); db = client.db('test'); db.listCollections({ name: { $not: { $regex: /system.+$/i } } }).toArray() .then(collections => { console.log(collections); client.close(); }); } }).catch(err => { console.log(`> Failed to connect mongoDB - ${err}`); process.exit(); });

       
      error:
       

      MongoServerError: can't get regex from filter doc Error parsing value [{$not [{$regex {"pattern": "system.+$", "options": "i"}}]}] to RegEx: Must specify $regex field
          at Connection.onMessage (/Users/vidyasagar/Desktop/error mongodb/node_modules/mongodb/lib/cmap/connection.js:210:30)
          at MessageStream.<anonymous> (/Users/vidyasagar/Desktop/error mongodb/node_modules/mongodb/lib/cmap/connection.js:63:60)
          at MessageStream.emit (node:events:378:20)
          at processIncomingData (/Users/vidyasagar/Desktop/error mongodb/node_modules/mongodb/lib/cmap/message_stream.js:132:20)
          at MessageStream._write (/Users/vidyasagar/Desktop/error mongodb/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
          at writeOrBuffer (node:internal/streams/writable:400:12)
          at _write (node:internal/streams/writable:341:10)
          at MessageStream.Writable.write (node:internal/streams/writable:345:10)
          at TLSSocket.ondata (node:internal/streams/readable:750:22)
          at TLSSocket.emit (node:events:378:20) {
        ok: 0,
        code: 8000,
        codeName: 'AtlasError',
        [Symbol(errorLabels)]: Set(0) {}
      }

       

      What driver and relevant dependency versions are you using?

      • Node version: 15.8.0
      • Mongo DB version: 5.0.4
      • mongodb driver npm package: 4.8.0

      Steps to reproduce?

      • Create an Atlas free connection
      • Use the Atlas connection url and connect to Mongo DB
      • list the collections with a regex
      • see error

        1. adapter.js
          0.7 kB
          PM Bot
        2. Screenshot 2022-07-22 at 10.43.36 AM.png
          630 kB
          PM Bot

            Assignee:
            daria.pardue@mongodb.com Daria Pardue
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: