-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
54 lines (43 loc) · 1.3 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var url = 'mongodb://localhost:27017/testDB';
var insertDocument = function(db, callback) {
var users = [];
for(var i = 0;i<10000;i++){
var user = {name:"mohan"+i , age:i , cars : "lambo"+i}
users.push(user)
}
db.collection('testTable').insert(users,function(err,result){assert.equal(err,null);callback();})
};
app.get('/', function (req, res) {
res.send('Hello World');
})
app.get('/insertBunchData',function(req,res){
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
insertDocument(db, function() {
res.send("inserted")
});
});
})
app.get('/getData',function(req,res){
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
db.collection('testTable').find({name:"mohan9944"}).toArray(function(err,objs){
res.send(JSON.stringify(objs))
});
// var data = []
// console.log(cursor)
// cursor.each(function(err, doc,cb) {
// assert.equal(err, null);
// console.log(cursor)
// })
});
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})