4
votes

I am currently new to MongoDB and NodeJS and I would like to know what the options useNewURLParser and useCreateIndex do.

const mongoose = require("mongoose");

mongoose.connect("mongodb://127.0.0.1:27017/task-manager-api",
{
    useNewUrlParser: true,
    useCreateIndex: true
})

1
See the doc with all the details: mongoosejs.com/docs/connections.html#optionsXavierBrt

1 Answers

4
votes

MongoDB has two connection string formats. The old format is now deprecated and uses an old URL format. There are mongodb+srv:// URLs, and simple mongodb:// URLs. If you are using the new format (you probably are by default), the new URL parser drops support for the old style urls.

useCreateIndex: Again previously MongoDB used an ensureIndex function call to ensure that Indexes exist and, if they didn't, to create one. This too was deprecated in favour of createIndex. the useCreateIndex option ensures that you are using the new function calls.

Reference:

https://mongoosejs.com/docs/connections.html#options https://mongoosejs.com/docs/deprecations.html