Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda