Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test Mongo
{
"name": "testmongo",
"version": "0.1.0",
"description": "test mongo speed",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"mongodb": "^1.4.22"
},
"devDependencies": {
"debug": "^2.1.0"
}
}
/*
Run
`npm install`
before running this
*/
var dbC = require('mongodb').MongoClient;
var debug = require('debug')('testmongo');
var insert = function() {
var url = "mongodb://localhost:27017/test";
dbC.connect(url, function(err, db) {
if (err) {
debug("Connection failed " + JSON.stringify(err));
} else {
var doc = db.collection('doc');
var x = [];
for (var i = 0; i < 100000; i++) {
x.push({y : i });
}
debug('before insert');
doc.insert(x, function (err, result) {
if (err) {
debug(i + " NO!" + JSON.stringify(err));
} else {
debug(i + ' YES insert' + JSON.stringify(result));
}
});
db.close();
debug('after insert');
}
});
};
insert();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment