Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Filter the populated data and then paginate in Mongodb

Hello I am trying to populate the data and then trying to paginate that data. Here is the example

Schema A (Users)

{
  name: 'Demo',
  postId: 'someObjectId',
}

Schema B (Posts)

{
  id: 'someObjectId',
  postName: 'Post 1',
  date: 'date of creation'
}

Here is my code

const users = UserModel.find({
  name: 'Demo'
}).populate({
   path: 'postId',
   select: 'date',
   match: {'postId.date' : {$lt: 'today'}}
}).page(pagination).limit(20)

Not getting the result needed. Can someone point out what's wrong?

NOTE: I have just given the overview. Please don't take it as real code. I know I haven't written what we would write in javascript

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A populate have following things:

Post.find({})
.populate([
    // here array is for our memory. 
    // because may need to populate multiple things
    {
        path: 'user',
        select: 'name',
        model:'User',
        options: {
            sort:{ },
            skip: 5,
            limit : 10
        },
        match:{
            // filter result in case of multiple result in populate
            // may not useful in this case
        }
    }
]);
.exec((err, results)=>{
   console.log(err, results)
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!