-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetData.js
40 lines (40 loc) · 1.29 KB
/
getData.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
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var db = new Db('miao_test', new Server('localhost', 27017));
var timeOut = 15; //停盘时间 插入今天领涨板块;
var dealData = {
findData : function(col,data){
var $this = this;
var timer = $this.getTime();
var date = new Date();
db.open(function(err, db){
if(err) {
console.log('Σ(っ °Д °;)っ 你他喵的忘记开启服务器辣');
}else{
db.collection(col,function(err,collection){
if(err) throw err;
else{
collection.find({'created_at' : {"$gte": timer}}).toArray(function(err,docs){
if (!docs.length && date.getHours() >= timeOut) {
collection.insert(data,function(insErr,insDoc){
if (insErr) {
throw 'mongodb' + insErr;
}else{
//有待补充嗷~~~
}
});
}else{
//
}
db.close();
});
}
});
}
})
},
getTime : function(){
return new Date(new Date().getFullYear() + '-' + Math.floor(new Date().getMonth() + 1) + '-' + new Date().getDate() + ' 00:00:00.0').getTime()
}
}
module.exports = dealData;