skip to Main Content

Mongodb – When there are two objects inside an array in Mongoose, how can i populate them?

router.get('/mypage/myreport-comment', catchAsync( async(req, res) => { const { id } = req.user; const { page } = req.query; const totalPost = await Comment.find({'reports.user': id}).populate('reports.user'); //.countDocuments({}); let { startPage, endPage, hidePost, maxPost, totalPage, currentPage } = myPageCommentPaging(page, totalPost); const comments =…

VIEW QUESTION

Mongodb – Trying to populate blogs in user but not working – mongoose

user.ts import mongoose from "mongoose"; const UserSchema=new mongoose.Schema({ _id:mongoose.Types.ObjectId, name:{ type:String, require:true }, email:{ type:String, require:true }, password:{ type:String, require:true, }, liked:[{ type: mongoose.Types.ObjectId, ref:'blogs', require:true }], myBlog:[{ type: mongoose.Types.ObjectId, ref:'blogs', require:true }] }) module.exports=mongoose.models.users||mongoose.model('users',UserSchema) blogs.ts import mongoose from "mongoose";…

VIEW QUESTION
Back To Top
Search