8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mongooseで列挙体(enum)を利用する

Last updated at Posted at 2015-02-23

使い方

enumはString型に指定する。
バリデーションの設定なので、ここで設定された値以外を入れようとするとエラーになるらしい。

var userSchema  = mongoose.Schema({
    uid : { type: String, required:true, index: {unique:true} },
    name: { first: String, last: String },
    age : { type: Number, min: 1 },
    gender : { type: String, enum: ['male', 'female', 'neuter'] }
});

参考

Mongoose学習#1「とりあえず使えるレベル」
http://yone-public.blogspot.jp/2012/11/mongoose1.html

If I never try, I'll never know: Node.jsが面白い件④ MongoDBで遊ぶ 〜Mongoose編その①〜
http://intink.blogspot.jp/2012/12/nodejs-mongodb-mongoose.html

Mongoose Validation v3.8.23
http://mongoosejs.com/docs/validation.html

Mongoose ODM
http://mongoosejs.com/docs/2.7.x/docs/schematypes.html

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?