Created
July 28, 2018 11:28
Creation method in Mongoose.js, alternative to custom constructor or hooks
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
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
/** | |
* Article Schema | |
*/ | |
var ArticleSchema = new Schema({ | |
created: { | |
type: Date, | |
default: Date.now | |
}, | |
title: { | |
type: String, | |
default: '', | |
trim: true, | |
required: 'Title cannot be blank' | |
}, | |
url: { | |
type: String, | |
trim: true, | |
default: '', | |
required: 'Url cannot be blank' | |
}, | |
content: { | |
type: String, | |
default: '', | |
trim: true | |
}, | |
user: { | |
type: Schema.ObjectId, | |
ref: 'User' | |
} | |
}); | |
mongoose.model('Article', ArticleSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment