Created
October 17, 2017 10:51
-
-
Save theneva/87bd5a59723044a8bac9a5ac04db49af to your computer and use it in GitHub Desktop.
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
const mongoose = require('mongoose') | |
mongoose.connect( | |
'mongodb://localhost/test', | |
{ useMongoClient: true }, | |
err => { | |
const bookSchema = new mongoose.Schema({ | |
title: { type: String, required: true }, | |
}); | |
const seriesSchema = new mongoose.Schema({ | |
name: { type: String, required: true }, | |
books: [bookSchema], | |
}); | |
const Series = mongoose.model('Series', seriesSchema); | |
if (err) { | |
console.error(err) | |
return; | |
} | |
const s = new Series({ | |
name: 'Mistborn', | |
books: [ | |
{ title: 'The Final Empire' }, | |
{ title: 'The Well of Ascension' }, | |
], | |
}); | |
s.save((err, res) => { | |
if (err) { | |
console.error(err); | |
} | |
console.log('saved', res); | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment