Created
November 28, 2014 11:31
-
-
Save gilbertwat/c8cdcf7c4ba345c6f258 to your computer and use it in GitHub Desktop.
Test Mongo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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