Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created August 16, 2012 17:48
Show Gist options
  • Save aheckmann/3372051 to your computer and use it in GitHub Desktop.
Save aheckmann/3372051 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var assert = require('assert')
console.log('\n===========');
console.log(' mongoose version: %s', mongoose.version);
console.log('========\n\n');
mongoose.connect('localhost', 'testing_1050');
mongoose.connection.on('error', function () {
console.error('connection error', arguments);
});
mongoose.connection.on('open', function () {
var schema = new mongoose.Schema({
level1: {
level2: {}
}
});
var model = mongoose.model('model', schema);
var inst = new model();
if (!inst.level1.level2) {
inst.level1.level2 = {};
}
inst.level1.level2.dt = {
prop1: 'value1'
};
console.log('Is modified - ' + inst.isModified('level1'));
inst.save(function(err) {
model.findOne(function(err, rec) {
rec.level1.level2 = {
prop1: 'newValue2'
};
console.log('Is modified on a record from db - ' + rec.isModified('level1'));
done()
});
});
});
function done (err) {
if (err) console.error(err.stack);
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