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

127
Views
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
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!