'How do I create a likes and dislikes button with multiple users and comments
I've been troubling a lot lately a few days and still haven't solve this so I feel like anyone can help me through this?
So basically let say I have a model for my users comments likes dislikes
Now the code something like this
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const ipSchema = new Schema({
ip:{type:String},
uid:{type:String}
},{
timestamps:true
})
const Ip = mongoose.model('Ip',ipSchema)
module.exports = Ip
Just don't mind the ip address..I just need the ip address to get who users is interacting my website, but this is for the users.
for the comments it is something like this
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const commentsSchema = new Schema({
uid:{type:String,required:true},
comment:{type:String,required:true},
likes:{type:Number},
dislikes:{type:Number}
})
const Comments1 = mongoose.model('commentsNatsuo',commentsSchema)
module.exports = Comments1
and for the likes and dislikes model
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const likesSchema = new Schema({
main_uid:{type:String,required:true},
reactor_uid:{type:String,required:true},
like_state:{type:Boolean},
})
const likes = mongoose.model('likes',likesSchema)
module.exports = likes
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const dislikesSchema = new Schema({
main_uid:{type:String,required:true},
reactor_uid:{type:String,required:true},
dislike_state:{type:Boolean},
})
const dislikes = mongoose.model('dislikes',likesSchema)
module.exports = dislikes
So what I want to happen is that when a comment is available by a certain user who owns the comment he/she gonna get a like/dislikes and obviously it will post in likes and dislikes but the thing is if he/she unlike/undislike I want it to edit so I will use put. I uses state_likes and state_dislikes for any user who will take back their likes/dislikes, but I'm already lost here when I did it in frontend
Ok, now so basically my point here is that my problem is how I can do this in my frontend and do it at the same time in backend I tried to discuss this in my problem here. But since it is not really understable to anyone I feel like I shrink a bit. I want to done this so badly..I really make a project about this before about getting likes and dislikes in comment but I still lose it but I wanna really solve it now so I hope someone can get me through this. Thank you very much.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
