1const mongoose = require('mongoose');
2const Schema = mongoose.Schema;
3
4const personSchema = Schema({
5 _id: Schema.Types.ObjectId,
6 name: String,
7 age: Number,
8 stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }]
9});
10
11const storySchema = Schema({
12 author: { type: Schema.Types.ObjectId, ref: 'Person' },
13 title: String,
14 fans: [{ type: Schema.Types.ObjectId, ref: 'Person' }]
15});
16
17const Story = mongoose.model('Story', storySchema);
18const Person = mongoose.model('Person', personSchema);