1const author = new Person({
2 _id: new mongoose.Types.ObjectId(),
3 name: 'Ian Fleming',
4 age: 50
5});
6
7author.save(function (err) {
8 if (err) return handleError(err);
9
10 const story1 = new Story({
11 title: 'Casino Royale',
12 author: author._id // assign the _id from the person
13 });
14
15 story1.save(function (err) {
16 if (err) return handleError(err);
17 // that's it!
18 });
19});
1var mongoose = require('mongoose')
2 , Schema = mongoose.Schema
3
4var eventSchema = Schema({
5 title : String,
6 location : String,
7 startDate : Date,
8 endDate : Date
9});
10
11var personSchema = Schema({
12 firstname: String,
13 lastname: String,
14 email: String,
15 gender: {type: String, enum: ["Male", "Female"]}
16 dob: Date,
17 city: String,
18 interests: [interestsSchema],
19 eventsAttended: [{ type: Schema.Types.ObjectId, ref: 'Event' }]
20});
21
22var Event = mongoose.model('Event', eventSchema);
23var Person = mongoose.model('Person', personSchema);
24
1User = new Schema({
2 places:[{type: Schema.Types.ObjectId, ref:'Place'}],
3 shouts:[{type: Schema.Types.ObjectId, ref:'Shout'}]
4});
5Place = new Schema({
6 name:String,
7 description:String,
8});
9Shout = new Schema({
10 content:String,
11});