Created
May 28, 2014 13:20
-
-
Save maxclaus/fbb8b224c2a6c653f7d9 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env node | |
var MongoClient = require('mongodb').MongoClient, | |
format = require('util').format, | |
async = require('async'); | |
MongoClient.connect('mongodb://127.0.0.1:27017/test_mongo', function(err, db) { | |
if(err) throw err; | |
var collection = db.collection('test_insert'); | |
var startTime = new Date(); | |
collection.remove({}, function(err) { | |
if (err) return console.log('remove err: ', err); | |
console.log('removed all'); | |
async.timesSeries(1000000, insert, function(err) { | |
if (err) return console.log('end err: ', err); | |
count(); | |
}); | |
}); | |
function insert (n, next) { | |
collection.insert({ my_index: n }, function(err) { | |
if (err) return next('insert err: ', err); | |
console.log('insert [%s] completed', n); | |
next(); | |
}); | |
} | |
function count () { | |
collection.count(function(err, count) { | |
if (err) return console.log('count err: ', err); | |
console.log(format("===> count = %s", count)); | |
var endTime = new Date(); | |
console.log('start [%s]\nend [%s]', startTime, endTime); | |
db.close(); | |
}); | |
} | |
}); |
Author
maxclaus
commented
May 28, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment