-
Notifications
You must be signed in to change notification settings - Fork 2
/
mongoose.js
57 lines (54 loc) · 1.14 KB
/
mongoose.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
(function () {
var mongoose = require('mongoose');
var Flow = require('../lib/flow.js').Flow;
var now = new Date();
mongoose.connect('mongodb://localhost/node_flow');
mongoose.model(
'Example',
new mongoose.Schema({
date: Date
})
);
var Example = mongoose.model('Example');
// Callback style
var example = new Example({
date: now
});
example.save(function (err) {
if (err) {
console.log('error', err);
return;
}
Example.find({}, [], function (err, examples) {
if (err) {
console.log('error', err);
return;
}
console.log(examples);
console.log('complete');
})
});
// Flow style
var root = Flow.serial(
function (flow) {
var example = new Example({
date: now
});
example.save(flow.next);
},
function (flow) {
Example.find({}, [], flow.next);
},
function (flow, examples) {
console.log(examples);
flow.next();
}
);
root.onError = function (err) {
console.log('error', err);
};
root.onComplete = function () {
console.log('complete');
};
root.start();
})();