node.js - Restrict mongoose field values -
i'm trying create:
var mongoose = require('mongoose'); var feelingschema = new mongoose.schema({ userid: string, feelingdate: date, feelingtimeofday: string, feelingvalue: string } );
how restrict value of field feelingvalue limited set, ['happy', 'angry', 'shocked']
i'm using version 3.8.23 of mongoose
you can constrain string field set of enumerated values enum
attribute in schema definition:
var feelingschema = new mongoose.schema({ userid: string, feelingdate: date, feelingtimeofday: string, feelingvalue: { type: string, enum: ['happy', 'angry', 'shocked'] } } );
Comments
Post a Comment