-
-
Save aheckmann/12f9ad103e0378db6afc to your computer and use it in GitHub Desktop.
This file contains 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'); | |
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