forked from mccormicka/Mockgoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
44 lines (37 loc) · 1.15 KB
/
test.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
// Whether to use old or new Mongoose
//var old = false;
//var mongoose = require(old ? 'mockgoose/node_modules/mongoose' : 'mongoose');
var mongoose = require('mongoose');
require('./Mockgoose')(mongoose);
var SomeSchema = new mongoose.Schema({
foo: String,
});
SomeSchema.statics.findAndExec = function(id) {
var model = this;
model.find({}, function(err, data) {
console.log("data from find:", data);
model.findByIdAndUpdate(id, {
foo: 'blue'
}, {
new: true
}, function(e, result) {
console.log("data from findByIdAndUpdate", e, result);
if (e) throw e;
console.assert(result !== null, 'result shall not be null');
console.log('Done!', result);
});
});
};
var Some = mongoose.model('Some', SomeSchema);
mongoose.connect('mongodb://localhost/whatever', onConnected);
function onConnected() {
new Some({
foo: 'red',
}).save(function(er, mod) {
console.log(er, mod);
if (er) throw er;
process.nextTick(function() {
Some.findAndExec(mod.id);
});
});
}