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

useNewUrlParser: true causes "command find requires authentication"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.1.13
    • Fix Version/s: 3.2.0
    • Component/s: None
    • Labels:
      None

      Description

      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{{}}

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: