Mongoose Model Parameters

Hi, I just started playing with Mongoose. Seems pretty awesome!

Now, based on the background of Django, how to implement one type of parameter fields, for example:

STATUS_OPTIONS : [{"Open",1},{"Closed",2},{"Pending",3"}] status: { type:String, required:true, options:STATUS_OPTIONS }, 

So that it can be set as status = Open or something like that.

Or should it just be the normal String field, and I set it accordingly in my application?

+4
source share
2 answers

You can restrict the Mongoose schema string field to a set of enumeration values ​​with the enum attribute:

 var s = new Schema({ status: { type: String, enum: ['Open', 'Closed', 'Pending'] } }); 
+8
source

What you are trying to do are links to some features, right? Probably as a field type enum .

Well, you might be lucky if you just use String or use a different scheme (but if you only need Closed, Open, Pending strings, this is not needed).

0
source

All Articles