About mongo’s useNewUrlParser warning

Recently I got this warning when trying to create a new MongoDB application

(node:28962) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

Turns out I’m the first few to use the new MongoDB driver released on npm over the weekend.

The new URL parser has no big changes (yet). Currently it only forces you to put the port into the URL

You can resolve the above warning by changing from

MongoClient.connect("mongodb://localhost:27017")

to

MongoClient.connect("mongodb://localhost:27017", { useNewUrlParser: true })

4 Replies to “About mongo’s useNewUrlParser warning”

  1. Sorry Can I ask A Question Please ? About the URL Can you rewrite the new parser with the situation that the URL didn’t have any PORT ? Because I’m having a problem at there ? Please kindly help me If you have any ideas
    Thanks and Best Regards

    Reply

    1. Why, you don’t have the port information? it should be 27017, the default port 🙂

      Reply

  2. Passing newUrlParser:true option to mongoose.connect causes the following issue when trying to do model.findOne:

    { MongoError: user is not allowed to do action [find] on [dbName.CollectionName]
    at queryCallback ………….
    …………………………
    …………………………
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    name: ‘MongoError’,
    message: ‘user is not allowed to do action [find] on [dbName.CollectionName]’,
    ok: 0,
    errmsg: ‘user is not allowed to do action [find] on [dbName.CollectionName]’,
    code: 8000,
    codeName: ‘AtlasError’,
    [Symbol(mongoErrorContextSymbol)]: { }
    }

    Removing the options stops the error, however it starts showing the DeprecationWarning warning.

    (node:4185) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

    And yes, I’m using MongoDB Atlas.

    Reply

    1. You should update your Mongoose, the new version properly use this option internally

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.