Last active
July 26, 2020 08:18
-
-
Save heytulsiprasad/2986f7ee40b4a90203fcf7d1faf568af to your computer and use it in GitHub Desktop.
A comprehensive user profile mongoose model
This file contains hidden or 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
| const mongoose = require("mongoose"); | |
| const Schema = mongoose.Schema; | |
| // Create Schema | |
| const PostSchema = new Schema({ | |
| user: { | |
| type: Schema.Types.ObjectId, | |
| ref: "users", | |
| }, | |
| text: { | |
| type: String, | |
| required: true, | |
| }, | |
| name: { | |
| type: String, | |
| }, | |
| avatar: { | |
| type: String, | |
| }, | |
| likes: [ | |
| { | |
| user: { | |
| type: Schema.Types.ObjectId, | |
| ref: "users", | |
| }, | |
| }, | |
| ], | |
| comments: [ | |
| { | |
| user: { | |
| type: Schema.Types.ObjectId, | |
| ref: "users", | |
| }, | |
| text: { | |
| type: String, | |
| required: true, | |
| }, | |
| name: { | |
| type: String, | |
| }, | |
| avatar: { | |
| type: String, | |
| }, | |
| date: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }, | |
| ], | |
| date: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }); | |
| module.exports = Post = mongoose.model("post", PostSchema); |
This file contains hidden or 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
| const mongoose = require("mongoose"); | |
| const Schema = mongoose.Schema; | |
| // Create Schema | |
| const ProfileSchema = new Schema({ | |
| user: { | |
| type: Schema.Types.ObjectId, | |
| ref: "users", | |
| }, | |
| handle: { | |
| type: String, | |
| required: true, | |
| max: 40, | |
| }, | |
| company: { | |
| type: String, | |
| }, | |
| website: { | |
| type: String, | |
| }, | |
| location: { | |
| type: String, | |
| }, | |
| status: { | |
| type: String, | |
| required: true, | |
| }, | |
| // Array | |
| skills: { | |
| type: [String], | |
| required: true, | |
| }, | |
| bio: { | |
| type: String, | |
| }, | |
| githubusername: { | |
| type: String, | |
| }, | |
| // Array of objects | |
| experience: [ | |
| { | |
| title: { | |
| type: String, | |
| required: true, | |
| }, | |
| company: { | |
| type: String, | |
| required: true, | |
| }, | |
| location: { | |
| type: String, | |
| }, | |
| from: { | |
| type: Date, | |
| required: true, | |
| }, | |
| to: { | |
| type: Date, | |
| }, | |
| current: { | |
| type: Boolean, | |
| default: false, | |
| }, | |
| description: { | |
| type: String, | |
| }, | |
| }, | |
| ], | |
| // Array of objects | |
| education: [ | |
| { | |
| school: { | |
| type: String, | |
| required: true, | |
| }, | |
| degree: { | |
| type: String, | |
| required: true, | |
| }, | |
| fieldofstudy: { | |
| type: String, | |
| required: true, | |
| }, | |
| from: { | |
| type: Date, | |
| required: true, | |
| }, | |
| to: { | |
| type: Date, | |
| }, | |
| current: { | |
| type: Boolean, | |
| default: false, | |
| }, | |
| description: { | |
| type: String, | |
| }, | |
| }, | |
| ], | |
| social: { | |
| youtube: { | |
| type: String, | |
| }, | |
| twitter: { | |
| type: String, | |
| }, | |
| facebook: { | |
| type: String, | |
| }, | |
| linkedin: { | |
| type: String, | |
| }, | |
| instagram: { | |
| type: String, | |
| }, | |
| }, | |
| date: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }); | |
| const Profile = mongoose.model("profile", ProfileSchema); | |
| module.exports = Profile; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Self Notes
mongo idof their own.