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

useNewUrlParser: true causes "command find requires authentication"

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.0
    • Affects Version/s: 3.1.13
    • Component/s: None

      this code works fine when useNewUrlParser === false

      const MongoClient = require('mongodb').MongoClient
      const fs = require('fs')
      const mongoUrl = "mongodb://cortex-mongo-0.cortex-mongo.default,cortex-mongo-1.cortex-mongo.default,cortex-mongo-2.cortex-mongo.default/AnalyticsUi?ssl=true&authMechanism=MONGODB-X509&replicaSet=rs0"

      const mongoOpts = {
        "cert": "keys/mongo-client.pem",
        "key": "keys/mongo-client.pem",
        "ca": "keys/ca.crt"
      }

      const ROOT_PATH = process.cwd()

      const options = {
        sslKey: fs.readFileSync(ROOT_PATH + '/' + mongoOpts['key']),
        sslCert: fs.readFileSync(ROOT_PATH + '/' + mongoOpts['cert']),
        sslCA: fs.readFileSync(ROOT_PATH + '/' + mongoOpts['ca']),
        useNewUrlParser: true
      }

      MongoClient.connect(mongoUrl, options, async (...args) => {
        const [err, client] = args
        if (err) console.error({err})
        if (client) {
         const db = client.db()
         const data = await db.collection('tasks').find({}).toArray()
         console.log('data', data)
      {{  }}}
      })

       

      But it throws the error "MongoError: command find requires authentication" if useNewUrlParser == true{{}}

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            zag2art Artur Zayats
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: