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

133
Views
Pagination with sub field in mongodb

I want to query from mongodb sub field and can pagination for it. Thankss!

  {
    "_id": "616d274c655e0000ee005f32",
    "subscription": [
      {
        "account_admin": "5fe5707399cc690013a159b2"
      },
      {
        "account_admin": "61b9bac72258040012e218d5"
      }
    ]
  },
  {
    "_id": "616fe5786b1b0000a9007a95",
    "subscription": [
      {
        "account_admin": "5fe5707399cc690013a159b2"
      },
      {
        "account_admin": "61b9bac72258040012e218d5"
      },
      {
        "account_admin": "5df739c4dfb7940013388e5f"
      },
      {
        "account_admin": "61b9b21daaa08000115f4da3"
      }
    ],
  }
]

How to find mongodb by field account_admin: "61b9bac72258040012e218d5" to data below (pagination if can)

====>

 [ 
  {
   "account_admin": "61b9bac72258040012e218d5"
  },
  {
   "account_admin": "61b9bac72258040012e218d5"
  }
 ];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Getting sub-fields are can be done with 'dot notation'. Pagination is simply using query.limit() and query.skip().

I've not tested the code but this should work.

const query = Model.find({ "subscription.account_admin": "61b9bac72258040012e218d5" });

query.limit(documentsPerPage);
query.skip(documentsPerPage * currentPageNumber);

const results = await query.exec();
about 4 years ago · Juan Pablo Isaza 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!