Skip to content

Instantly share code, notes, and snippets.

@eoanodea
Created February 12, 2020 16:14
Show Gist options
  • Save eoanodea/0c8c54510e79cfe24cb36e9293741c97 to your computer and use it in GitHub Desktop.
Save eoanodea/0c8c54510e79cfe24cb36e9293741c97 to your computer and use it in GitHub Desktop.
Post and Media Mongoose Schema
//Post Schema
const PostSchema = new mongoose.Schema({
text: {
type: String,
},
photo: {
data: Buffer,
contentType: String,
},
orientation: Number,
likes: [{type: mongoose.Schema.ObjectId, ref: 'User'}],
views: {type: Number, default: 0},
comments: [{
text: String,
created: { type: Date, default: Date.now },
postedBy: { type: mongoose.Schema.ObjectId, ref: 'User'}
}],
postedBy: {type: mongoose.Schema.ObjectId, ref: 'User'},
created: {
type: Date,
default: Date.now
},
type: {
type: String
}
})
//Media Schema
const MediaSchema = new mongoose.Schema({
text: {
type: String,
},
likes: [{type: mongoose.Schema.ObjectId, ref: 'User'}],
views: {type: Number, default: 0},
comments: [{
text: String,
created: { type: Date, default: Date.now },
postedBy: { type: mongoose.Schema.ObjectId, ref: 'User'}
}],
postedBy: {type: mongoose.Schema.ObjectId, ref: 'User'},
created: {
type: Date,
default: Date.now
},
type: {
type: String
},
updated: {
type: Date
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment