Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 11, 2012 01:01
Show Gist options
  • Save aheckmann/3695197 to your computer and use it in GitHub Desktop.
Save aheckmann/3695197 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');
var dbname = 'testing_cantsave';
console.log('dbname: %s', dbname);
mongoose.connect('localhost', dbname);
mongoose.connection.on('error', function () {
console.error('connection error', arguments);
});
var schema = new Schema({
name : { type: String, required: true }
,customer : { type: Schema.ObjectId, required: true , ref: 'Customer'}
,extension : { type: Number, required: true}
,timeout : { type: Number, default: 5}
,ddi : { type: String}
,email : { type: String}
,description : { type: String}
,pin : { type: Number}
,digits : [ { digit : { type : String}, target : { type: String} }]
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A({
name: 'cantsave'
, extension: 33
, customer: new mongoose.Types.ObjectId });
a.save(function (err, a) {
if (err) return done(err);
A.findById(a, function (err, doc) {
console.error('found', doc);
done(err);
});
})
});
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