Skip to content

Instantly share code, notes, and snippets.

@theneva
Created October 17, 2017 10:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save theneva/87bd5a59723044a8bac9a5ac04db49af to your computer and use it in GitHub Desktop.
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