Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created December 13, 2011 17:11
Show Gist options
  • Save aheckmann/1472975 to your computer and use it in GitHub Desktop.
Save aheckmann/1472975 to your computer and use it in GitHub Desktop.
var mongoose = require('./../mongoose');
mongoose.connect('localhost', 'testing_596');
function validatePresenceOf (value) {
console.error('validating ', value);
if (value === null) return false;
return value;
};
var AccountSchema = new mongoose.Schema({
balance: {type: Number, validate: [validatePresenceOf, 'nooooooooooooooooo']}
});
var A = mongoose.model('Customer', new mongoose.Schema({
name : String
, email : String
, accounts: [AccountSchema]
}));
mongoose.connection.on('open', function () {
var a = new A;
a.accounts.push({ balance: 3.43});
a.accounts.push({ balance: "" });
a.accounts.push({ balance: "twenty" });
a.save(function (err) {
if (err) console.error(err.stack||err);
console.error('isnew %s', a.isNew);
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