Skip to content

Instantly share code, notes, and snippets.

@ninjasort
Created April 1, 2017 14:19
Show Gist options
  • Save ninjasort/83f697d0549e9e4535bc5803669d8d7d to your computer and use it in GitHub Desktop.
Save ninjasort/83f697d0549e9e4535bc5803669d8d7d to your computer and use it in GitHub Desktop.
Schema Design
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