Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created May 1, 2012 17:01
Show Gist options
  • Save aheckmann/2569624 to your computer and use it in GitHub Desktop.
Save aheckmann/2569624 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.connect('localhost', 'testing_876');
mongoose.connection.on('error', function () {
console.error(arguments);
});
var schema = new Schema({
name: String
, active : {type:Boolean, default: false }
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A({ name: '876' });
a.save(function (err, a) {
if (err) return console.error(err.stack||err);
// confirm the data in the db by skipping mongoose
//A.collection.findOne({ _id: a._id }, function (err, doc) {
// console.error(doc);
//});
A.findOne({ _id: a._id }, ['name','active'], function (err, doc) {
if (err) console.error(err);
console.error(doc.active);
mongoose.connection.close();
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment