-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestAgendaQuery.js
70 lines (51 loc) · 1.38 KB
/
testAgendaQuery.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Created by chaclus on 16/9/3.
*/
var Agenda = require('agenda');
var ObjectId = require('sails-mongo/node_modules/mongodb').ObjectID;
var mongoConnectionString = "mongodb://192.168.3.30/agenda";
var agenda = new Agenda({db: {address: mongoConnectionString}}, function () {
// query()
findById();
});
var page = 1;
var size = 10;
var query = function () {
//{name: 'show'}
var q = {};
agenda.jobs(q, function (err, jobs) {
console.log("jobs : " + jobs);
if(jobs.length > 0) {
jobs[0].disable();
jobs[0].save();
}
});
var o = {};
if (size) {
o.limit = size;
} else {
o.limit = 10;
}
if (page) {
o.skip = (page) * o.limit;
} else {
o.skip = 0;
}
agenda._collection.count(q).then(function (result) {
console.log("jobs count : " + result);
agenda._collection.find(q, o).toArray(function (err, docs) {
console.log(docs)
})
});
};
var findById = function () {
var id = "57d0bb394a4953bb4f7f061f";
var objId = new ObjectId(id);
console.log('_id : ' + objId.toString());
agenda._collection.find({_id:objId}).toArray(function (err, docs) {
console.log(docs);
agenda._collection.find({_id:docs[0]._id}).toArray(function (error, ret) {
console.log(ret)
});
});
};