Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created May 15, 2012 00:09
Show Gist options
  • Save ovaillancourt/2698214 to your computer and use it in GitHub Desktop.
Save ovaillancourt/2698214 to your computer and use it in GitHub Desktop.
Shutting down after a bunch of mongoose transactions.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var FooSchema = new Schema({
dob: { type: Date},
num: {type : Number},
});
Foo = mongoose.model('Foo', FooSchema);
mongoose.connect("mongodb://test:test@127.0.0.1/test", function(){
console.log('connected!');
});
console.log('calling remove');
Foo.remove({}, function(err) {
var f;
f = new Foo({
dob: Date.now(),
num: 1,
test : {
bla: 2
}
});
console.log('calling save');
f.save(function(err) {
Foo.find().$or([{'num' : 1},{'test.bla' : 3}]).run(function(err, doc) {
console.log(doc);
mongoose.disconnect(function(){
console.log('disconnected! byebye!');
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment