Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:, // 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