Connecting To a Database

suggest change

To connect to a mongo database from node application we require mongoose.

Installing Mongoose Go to the toot of your application and install mongoose by

npm install mongoose

Next we connect to the database.

var mongoose = require('mongoose');

//connect to the test database running on default mongod port of localhost  
mongoose.connect('mongodb://localhost/test');
//Connecting with custom credentials
mongoose.connect('mongodb://USER:PASSWORD@HOST:PORT/DATABASE');

//Using Pool Size to define the number of connections opening
//Also you can use a call back function for error handling
mongoose.connect('mongodb://localhost:27017/consumers', 
                 {server: { poolSize: 50 }}, 
                 function(err) {
                    if(err) {
                        console.log('error in this')
                        console.log(err);
                        // Do whatever to handle the error 
                    } else {
                        console.log('Connected to the database');
                    }
                });

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


MongoDB:
* Connecting To a Database

Table Of Contents
1 npm
41 cli
43 grunt
59 Hack
64 ES6
67 Redis
69 MongoDB
86 MongoDB
87 Lodash
91 CORS
105 N-API
108 Require