2017-07-31 11:33:31 +05:30

27 lines
459 B
JavaScript

'use strict'
const MongoClient = require('mongodb').MongoClient
const url = 'mongodb://localhost:27017/test';
var count = 0
var max = 1000
MongoClient.connect(url, function(err, db) {
if (err) { throw err }
const collection = db.collection('data')
function insert (err) {
if (err) throw err
if (count++ === max) {
return db.close()
}
collection.insert({
value: Math.random() * 1000000
}, insert)
}
insert()
})