Created
August 23, 2012 23:00
-
-
Save aheckmann/3443083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// must use `doc.set` for all changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_noschema'); | |
mongoose.connection.on('error', function () { | |
console.error('connection error', arguments); | |
}); | |
var schema = new Schema({ | |
}, { _id: false, id: false, strict: false }); | |
var A = mongoose.model('A', schema); | |
mongoose.set('debug', true); | |
mongoose.connection.on('open', function () { | |
var a = new A({ name: 'noschema' }); | |
a.save(function (err, a) { | |
if (err) return done(err); | |
A.findOne(function (err, doc) { | |
console.error('found', doc); | |
doc.set('anything', 'sdf'); | |
doc.save(function (err) { | |
assert.ifError(err); | |
A.findOne(function (err, doc) { | |
assert.ifError(err); | |
console.error('found', doc); | |
doc.set('anything', undefined); | |
doc.save(function (err) { | |
assert.ifError(err); | |
A.findOne(function (err, doc) { | |
assert.ifError(err); | |
console.error('found', doc); | |
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