I'm trying to test my mongoDB queries in node.js. I'm using the native mongodb driver . Up until recently I was using tingodb . But this module is not supporting node mongodb 2.x.
So as far as I'm concernded I have two options 1. Not to update my mongoDB node module to 2.x (currently using 1.4). This is obviously a bad idea. 2. In my tests, I can either connect to a local mongoDB instance and test my code using it. The downside is that the tests might run slower. 3. Write some node code that will start/stop a mongo process on the local machine
What would be the best approach? Am I missing another npm mondule that can solve my problem?
Why not mongoose ?
npm install mongoose --save
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) {
console.log(err);
} else {
console.log('meow');
}
});
A good tutorial is here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.