Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created May 30, 2012 23:10
Show Gist options
  • Save aheckmann/2839487 to your computer and use it in GitHub Desktop.
Save aheckmann/2839487 to your computer and use it in GitHub Desktop.
var mongoose = require('./../mongoose');
var Schema = mongoose.Schema;
mongoose.connect('localhost', 'testing_10818776');
mongoose.connection.on('error', function () {
console.error(arguments);
});
var schema = new Schema({
name: String
, msg: [new Schema({ isRead: Boolean })]
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A;
a.name = 'test'
a.msg = [{isRead: false}]
a.save(function (err, a) {
if (err) return console.error(err.stack||err);
A.findById(a, function (err, doc) {
if (err) console.error(err.stack||err);
console.error('found', doc);
doc.msg.forEach(function (doc) {
doc.isRead = true;
});
doc.save(function (err) {
if (err) console.error(err.stack||err);
A.findById(a, function (err, doc) {
if (err) console.error(err.stack||err);
console.error('result', doc);
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
});
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment