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

426
Vistas
How to query and populate subdocuments only inside a document?

I have a collection as follows, enter image description here

i want to query and populate only reviews which has the fromUser userID '233232'
Right now my helper class is as follows,

 queryaggregateWithProject: function (model, matchedCond, prjCond) {
            return new Promise(function (resolve, reject) {
                model.aggregate([
                    {$match: matchedCond},
                    {$project: prjCond}
                ], function (error, data) {
                    if (error)
                        reject(error);
                    resolve(data);
                });
            })
        }

what should i pass for matchedCond and projCond?

Schema

module.exports = function () {
    var model = null;
    var modelName = '_purchase';
    try {
        model = dbService.getModel(modelName);
    } catch (error) {     

        var userSchema = dbService.createEntityDef({
            userId: {
                type: String
            },            
            urlPicture: {
                type: String
            }
        });
        var reviewSchema = dbService.createEntityDef({
            fromUser: userSchema,
            toUser: userSchema,
            rating: {
                type: Number
            },
            comment: {
                type: String
            }


        })


        var purchaseSchema = {
            _id: {
                type: dbService.getPrimaryKeyType(),
                index: true
            },
            purchaseId: {
                type: String
            },          
            reviews: [reviewSchema]

        };
        model = dbService.createModel(modelName, purchaseSchema, {
            name: 'text'
        }, modelName);
    }

    return model;
};
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your matchedCond

{ fromUser.userid : "youruserid" }

Your projCond

{ document: "$$ROOT" }

will return the objects with all properties.

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