Create a connection using the Mongoose.connect () method
Mongoose.conect (' Mongodb://localhost/myapp ');
The above code is linked to the MyApp database of MongoDB via the default port 27017. We can also set some specific parameters for the URL:
Mongoose.conect (' Mongodb://username:[email protected]:p ort/databasename?options ... ');
Options
The Connect method can accept an options object
Mongoose.connect (URI, options);
Here is the Options key
- DB-Set which database to connect to
- Server-Set up a connection service instance
- Replset-Set Connection Replset instance
- User-Set Login username
- Pass-Set the login user password
- Auth-Validate options
- Mongos-boolean If set to True the database is more reliable
For example:
var options = { db: {native_parser:true}, server: {poolsize:5}, Replset: {rs_name: ' Myreplicasetname '} , User: ' MyUserName ', Pass: ' MyPassword '}mongoose.connect (URI, options);
Mongoose Guide-Connection