You'll want to insert it where you're creating your mongo connection.
For example (using mongoose
)...
const mongoose = require("mongoose");
const { DATABASE } = process.env; // this a mongodb connection string that varies upon the NODE environment
const options = {
useNewUrlParser: true, // avoids DeprecationWarning: current URL string parser is deprecated
useCreateIndex: true, // avoids DeprecationWarning: collection.ensureIndex is deprecated.
useFindAndModify: false, // avoids DeprecationWarning: collection.findAndModify is deprecated.
useUnifiedTopology: true // avoids DeprecationWarning: current Server Discovery and Monitoring engine is deprecated
};
mongoose.connect(DATABASE, options); // connect to our mongodb database
Here's a Fullstack MERN boilerplate I created and use for my projects, which has an example of how to connect to a local mongo database. You can use it as a reference, if needed.