Skip to content

Instantly share code, notes, and snippets.

@eladcandroid
Created April 15, 2018 11:47
Show Gist options
  • Save eladcandroid/7cbd41ba2541018ce893c6d885bf792f to your computer and use it in GitHub Desktop.
Save eladcandroid/7cbd41ba2541018ce893c6d885bf792f to your computer and use it in GitHub Desktop.
Mongoose relational scheme
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Create a Schema and a Model
const BookSchema = new Schema({
title: String,
pages: Number
});
const AuthorSchema = new Schema({
name: String,
books: [BookSchema]
});
const Author = mongoose.model('author', AuthorSchema);
module.exports = Author;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment