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

173
Views
Count all items inside a collection entry

I have the collection:

    {'_id':'1',
     'n1':'a',
     'f4':'4rrf'},

    {'_id':2
     'k545':'aad5',
     '1dd':'1s',
     '1yh':'sxaa',
     '6uu':'jt',
     }]

Where all the entries are nested at the same level as '_id', I would like a query that count all the entries per '_id', with the following output:

{'_id':1,
 'count':2},
{'_id':2,
 'count':4
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use Aggregation Framework which has a array $size operator which you can use:

> db.mycollection.aggregate([{$project: { count: { $size:"$_id" }}}])
over 4 years ago · Santiago Trujillo 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!