Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created December 22, 2011 22:29
Show Gist options
  • Save aheckmann/1512125 to your computer and use it in GitHub Desktop.
Save aheckmann/1512125 to your computer and use it in GitHub Desktop.
var mongoose = require('./../mongoose');
mongoose.connect('localhost', 'testing_enumarray');
var ok = 'car figure'.split(' ');
function validator (v) {
return v.every(function (val) {
return !!~ok.indexOf(val)
});
}
var schema = new mongoose.Schema({
//tags: [{type:String, enum: ['figure','car']}] // doesn't work
tags: { type: [String], validate: validator }
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A;
a.tags = ['figure', 'car'];
console.error(a.schema.paths);
a.validate(function (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