[SERVER-4376] Determining array and document size (number of keys) without loading document to client Created: 27/Nov/11  Updated: 06/Dec/22  Resolved: 26/Dec/17

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

Type: New Feature Priority: Minor - P4
Reporter: Aristarkh Zagorodnikov Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 7
Labels: array, query, size
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

In our environment, the ability to determine array and document sizes without transferring them over the wire would be very welcome. I guess that existing syntax for queries ($size) would do nicely.
I actually wrote this request after I've read someone other's message in mongodb-user: http://groups.google.com/group/mongodb-user/browse_thread/thread/159eecb36444f402 and understood that I'm not the only one with such needs.



 Comments   
Comment by Asya Kamsky [ 26/Dec/17 ]

Size of arrays and other schema/document properties can be handled on the server (without bringing document back to client).

Comment by Asya Kamsky [ 02/Feb/17 ]

As of 3.4, aggregation supports fetching sizes of arrays, sizes strings and types of fields.

Future enhancements will include ability to extract all key names. This should enable pushing array and document analysis to the server without having to bring documents to the client.

Comment by Piyush Verma [ 02/Nov/12 ]

https://jira.mongodb.org/browse/SERVER-786 Seems Related.

Comment by Piyush Verma [ 02/Nov/12 ]

Aggregation framework would mean doing a project and looping over all the elements. Although this would happen server side, it aint be as fast as just reading the length (MetaData) of an Array.
Using aggregation framework for size would defeat the purpose.

Example use case:=
I want to query for Comments only if the size of comment_ids array is > 0
With Aggregation Framework I would query the comments and then return them If the length is > 0. I might as well fetch the entire data and do it client Side.

Comment by Scott Hernandez (Inactive) [ 27/Nov/11 ]

The new aggregation framework will have support for these types of aggregations, and transformations: SERVER-447

Comment by Alexander Slepoy [ 27/Nov/11 ]

In addition to size will be nice to add $avg(array.field), $min(array.field), $max(array.field) it would be used for different cases.

Generated at Thu Feb 08 03:05:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.