Sunday 26 January 2020

Moongoose populate NightMare

I am trying to create social events hosting site, and for that, I am using mongoose.I have three different schemas. EVENT schema, USER Schema, COMMENTS schema.The problem is every time I make a comment on any POST, USERNAME is posted alongside.But as soon as I update the USERNAME in USER schema it's not getting reflected in previously posted comments by the said USER.I am lost and need help.var mongoose = require("mongoose");var passportLocalMongoose = require("passport-local-mongoose");var UserSchema = new mongoose.Schema({name: String,city: String,username: String,gender: String,token: String,about: {type:String,default:"Please edit your about..."},phone: {type:String,default:"NA"},imageFile: {type:String,default:"https://res.cloudinary.com/de189qjwo/image/upload/v1579693244/user_1_xpcx6a.png"}});UserSchema.plugin(passportLocalMongoose)module.exports = mongoose.model("User", UserSchema);var mongoose = require("mongoose");var commentSchema = mongoose.Schema({text: String,author: {id: {type: mongoose.Schema.Types.ObjectId,ref: "User"},name: String}});module.exports = mongoose.model("Comment", commentSchema);router.get("/", middleware.isLoggedIn,function(req, res){var id = req.user._id;User.findById(id,(err,user)=>{Event.find({},(err,events)=>{Task.find({}, (err, tasks) => {res.render("homepage",{user:user,event:events,task: tasks})})})})});I think there's issue with POPULATE please help.

Submitted January 26, 2020 at 05:38AM by samtrastic

No comments:

Post a Comment