Skip to content

Instantly share code, notes, and snippets.

@heytulsiprasad
Created July 14, 2020 08:39
Show Gist options
  • Select an option

  • Save heytulsiprasad/a4e99115786234967c40ba52abf72ffc to your computer and use it in GitHub Desktop.

Select an option

Save heytulsiprasad/a4e99115786234967c40ba52abf72ffc to your computer and use it in GitHub Desktop.
Dealing with relational data inside schema (while making model)
const mongoose = require("mongoose")
const Schema = mongoose.Schema
const BookSchema = new Schema({
title: String,
pages: Number
})
const AuthorSchema = new Schema({
name: String,
age: Number,
books: [BookSchema]
})
const Author = mongoose.model("author", AuthorSchema)
module.exports = Author
// module.exports = mongoose.model("author", AuthorSchema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment