Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Last active December 14, 2015 07:49
Show Gist options
  • Save aheckmann/12f9ad103e0378db6afc to your computer and use it in GitHub Desktop.
Save aheckmann/12f9ad103e0378db6afc 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], validate: validator }
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A;
a.tags = ['figure', 'car'];
a.validate(function (err) {
if (err) console.error(err.stack);
else console.log('worked');
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