-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmongo.js
More file actions
83 lines (68 loc) · 1.71 KB
/
Copy pathmongo.js
File metadata and controls
83 lines (68 loc) · 1.71 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var async = require('async');
var faker = require('Faker');
var mongojs = require('mongojs');
var db = mongojs('test',["test","team"]);
var self = {};
self.insert = function(dataSize,done){
var run = [];
run.push(function(callback){
db.test.remove({},callback);
})
run.push(function(callback){
db.team.remove({},callback);
})
run.push(function(callback){
db.team.createIndex({id:1},callback);
});
run.push(function(callback){
db.test.createIndex({team:1},callback);
});
for(var i=0;i<dataSize;i++){
run.push(function(callback){
db.test.insert({
player:faker.Name.findName(),
email:faker.Internet.email(),
score:Math.floor(Math.random()*1000),
team:Math.floor(Math.random()*dataSize),
},callback);
});
run.push(function(callback){
db.team.count({},function(err,data){
db.team.insert({
city:faker.Address.city(),
country:faker.Address.ukCountry(),
id:data,
name:faker.Company.companyName().split(" ")[0].split(",")[0]
},callback);
})
});
}
console.time('mongo insert');
async.series(run,function(err,data){
// console.log(err);
console.timeEnd('mongo insert');
if(done) done();
});
}
self.find = function(dataSize,done){
var run = [];
console.time('mongo select');
db.test.find({},function(err,data){
data.forEach(function(player){
run.push(function(callback){
db.team.find({id:player.team},function(err,data){
if(!data[0].name) console.log('mongo error : team no name');
callback();
})
});
});
async.series(run,function(err,data){
// console.log(err);
console.timeEnd('mongo select');
if(done) done();
});
});
}
module.exports = function(type,dataSize,done){
return self[type](dataSize,done);
}