Last active
April 7, 2019 15:30
-
-
Save vincentntang/26f8a5d505e633a9dc8ac7b57f144da8 to your computer and use it in GitHub Desktop.
MongoDB Slack : POST vs AUTHORS one-to-many
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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` | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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