Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MongoDB Slack : POST vs AUTHORS one-to-many
// A post can have multiple authors
// An author can have many posts
// many-to-many relationship
{
Post: [
postID: 'postID',
postTitle: 'How to build a website'
postContent: '<div><p>HTML or markdown content here<p></div>'
authorID: ['AuthorID1','AuthorID2'] // We define many-to-many relationship here
],
Author: [
authorID: 'authorID',
authorName: 'John Doe'
authorTitle: 'Web Developer'
// postID: [PostID1, PostID2] // this is not necessary because we define it in `Post`
]
}
// A post has one author
// an author can have many posts
// one-to-many relationship (author : post)
{
Post: [
postID: 'postID',
postTitle: 'How to build a website'
postContent: '<div><p>HTML or markdown content here<p></div>'
authorID: 'authorID' // this defines foreign key for one-to-many or even one-to-one relationship
],
Author: [
authorID: 'authorID',
authorName: 'John Doe'
authorTitle: 'Web Developer'
// postID: [PostID1, PostID2] // this is not necessary because we define it in `Post`
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.