Skip to content

Instantly share code, notes, and snippets.

@krissnawat krissnawat/User.js
Created Feb 3, 2019

Embed
What would you like to do?
const mongoose = require('mongoose')
let UserSchema = new mongoose.Schema(
{
name: String,
email: String,
provider: String,
provider_id: String,
token: String,
provider_pic: String,
followers: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
],
following: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
]
}
)
UserSchema.methods.follow = function (user_id) {
if (this.following.indexOf(user_id) === -1) {
this.following.push(user_id)
}
return this.save()
}
UserSchema.methods.addFollower = function (fs) {
this.followers.push(fs)
}
module.exports = mongoose.model('User', UserSchema)
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.