Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Passing condition Mongoose NodeJS

I am trying to get list from my mongodb by passing a condition but anytime I print my condition, I get undefined.

async list(query: PaginationQuery): Promise<any> {
        const page = Number(query.page) - 1 || 0;
        let limit = Number(query.limit) || 20;
        const offset = page * limit;
        const sort = query.sort || 'createdAt';

        const archived = this.convertArchived(query.archived);

        const conditions = {
            ...query.conditions,
            ...(!archived
                ? { deletedAt: undefined }
                : { deletedAt: { $ne: undefined } })
        };
        console.log(`HELP MEEE xx ${JSON.stringify(query.conditions)}`)
        
        const data = await this.model
            .find(conditions)
            .select(query.projections)
            .skip(offset)
            .limit(limit)
            .sort(sort);

        const totalDocuments = await this.model.countDocuments(conditions);
        const pageCount = Math.ceil(totalDocuments / limit);

        const pagination = {
            page: page + 1,
            limit,
            sortedBy: sort,
            pageCount
        };
        
        return { data, pagination };
    }

This is my repo

public async listAll() {
        const conditions = { role: 'surf' };
        const data = { condition: conditions, page: 1, limit: 10 };
        const all = await this.list(data);
        
        return  all
    }

This does not take the condition into account and just returns all the users.

My Pagination query interface looks like this

export interface PaginationQuery {
    archived?: boolean | string;
    conditions?: any;
    page?: number;
    limit?: number;
    projections?: any;
    sort?: string | object;
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda