[SERVER-1144] Provide way to give counts of array attributes in projection Created: 24/May/10  Updated: 06/Dec/22  Resolved: 19/May/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.5.1
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Doug Hudson Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 8
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Participants:

 Description   

Obtaining counts for large attributes can be a pain. Approaches are to:
1) Return the entire array and examine length
2) group/reduce and output the length
3) map/reduce to get length
4) ensure documents maintain length attribute across document lifespan

I think being able to request embedded array length directly would be helpful.

Perhaps something like:
db.collection.find({}, {some_array: {$count: true}})



 Comments   
Comment by David Storch [ 19/May/17 ]

Closing as Gone Away per Asya's comment above. The documentation for the $size expression, which was added in version 2.6, is available here:

https://docs.mongodb.com/manual/reference/operator/aggregation/size/

Comment by Asya Kamsky [ 16/May/17 ]

This can be done via aggregation $project stage using $size expression.

Generated at Thu Feb 08 02:56:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.