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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -