Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I'm learning NodeJs.

To connect to and use MongoDB from NodeJS, I see a lot of examples using either Monk or Mongoose.

Are these two libraries equivalent? Do they have the same features or do they each have a specific purpose?

As a beginner with NodeJS, which should I use?

Here are some examples of code that uses Monk :

var mongo = require('mongodb'); 

var monk = require('monk'); 

var db = monk('localhost:27017/nodejsapp'); 

---- 

exports.userlist = function(db) { 

return function(req, res) { 

var collection = db.get('users'); 

collection.find({},{},function(e,docs){ 

res.render('userlist', {

 "userlist" : docs 

}); 

}); 

}; 

};

and here a sample that uses Mongoose :

var mongoose = require('mongoose'); 

---- 

mongoose.connect('localhost', 'test'); 

var db = mongoose.connection; 

db.on('error', console.error.bind(console, 'connection error:')); 

db.once('open', function callback() { 

console.log('Connected to DB'); 

}); 

var userSchema = mongoose.Schema({ 

username: { type: String, required: true, unique: true }, 

email: { type: String, required: true, unique: true }, 

password: { type: String, required: true}, 

});

1 Answer

0 votes
by (106k points)

If you are learning NodeJS and MongoDB, you really don’t need anything else -- in fact, MongoDB offers a free online class for MongoDB and NodeJS developers. No need for any additional wrappers.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
2 answers
0 votes
2 answers

Browse Categories

...