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

174
Views
How to get data with a cleaner way using mongoose?

I'm filtering the data based on a Boolean savedBoolean , and if that Boolean is not being inputted I'm getting all the data, this code works for now. But how to do it in a cleaner way since I'm duplicating the code.


let filteredReviews : any | undefined;
  if (savedBoolean === true || savedBoolean === false) {
    filteredReviews = await Interviewee.aggregate([{
      $project: {
        _id: 0,
        userId: 1,
        'interviews.review': 1,
      },
    },

    {
      $unwind: '$interviews',
    },
    {
      $match: {
        userId: '4',
        'interviews.review.saved': savedBoolean,
      },
    },
    {
      $group: {
        _id: '$interviews.review._id',
        review: {
          $first: '$interviews.review',
        },
      },
    },
    ]).skip((Number(page) - 1) * 3).limit(3);
  }

  if (savedBoolean === undefined) {
    filteredReviews = await Interviewee.aggregate([{
      $project: {
        _id: 0,
        userId: 1,
        'interviews.review': 1,
      },
    },
    {
      $match: {
        userId: '4',
      },
    },
    {
      $unwind: '$interviews',
    },

    ]).skip((Number(page) - 1) * 3).limit(3);
  }

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In MongoDB, the db.collection.remove() method removes documents from a collection. You can remove all documents from a collection, remove all documents that match a condition, or limit the operation to remove just a single document.

over 4 years ago · Santiago Trujillo 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!