Created
April 1, 2017 14:19
-
-
Save ninjasort/83f697d0549e9e4535bc5803669d8d7d to your computer and use it in GitHub Desktop.
Schema Design
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
var mongoose = require('mongoose') | |
var Schema = mongoose.Schema | |
/* | |
Creates a Schema | |
*/ | |
var BookSchema = new Schema({ | |
title: String, | |
published: { | |
type: Date, // sets the type | |
required: true, // sets a required value | |
default: Date.now, // sets a default value | |
unique: true // makes sure that this is unique entry | |
}, | |
keywords: Array, | |
author: { | |
type: Schema.ObjectId, // references another object | |
ref: User // references the User model and add it to this field | |
}, | |
detail: { | |
modelNumber: Number, | |
hardcover: Boolean, | |
reviews: Number, | |
rank: Number | |
} | |
}) | |
// Get the sub object from ==> data.detail.modelNumber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment