[DOCS-13183] Investigate changes in SERVER-33582: Add $bsonSize expression Created: 30/Oct/19  Updated: 13/Nov/23  Resolved: 13/Feb/20

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 4.3.3, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Major - P3
Reporter: Backlog - Core Eng Program Management Team Assignee: Jeffrey Allen
Resolution: Fixed Votes: 0
Labels: docs-grab-bag
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-33582 Add $bsonSize expression Closed
Related
Participants:
Days since reply: 3 years, 51 weeks, 6 days ago
Epic Link: DOCS: 4.4 Server Release Work

 Description   

Description

Downstream Change Summary

Adds a $bsonSize expression

Description of Linked Ticket

The query team has discussed and agreed to the following syntax and semantics:
Name: $bsonSize
Rejected alternative names: $bsonElementSize, $bsonObjSize
This expression takes an expression that evaluates to an object, and return the size of the object in bytes when encoded as BSON. The resulting size excludes any metadata in the document. Errors on non-nullish non-objects. If the expression is nullish, returns null.
Syntax:

{ $bsonSize: <Expression> } 

This will parse like all other unary expressions, and accept the argument by itself or as an array with one element.

Original Ticket Description

Twice in the last week someone asked how to compute object size (in bytes) in aggregation.

Once it was when they were trying to rewrite mapReduce job in agg (mapReduce has access to Object.bsonsize() method) and the other time when they were trying to compute in aggregation average size of certain oplog entries.

Seems like it could be useful and simple enough if it does exactly what Object.bsonsize() method does. Possible syntax: {$objSize:<expression-resolving-to-object>}. Alternative may be overloaded $bsonSize expression which takes any type and returns its size in bytes (usable for scalar types, arrays, objects, etc)

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 13/Feb/20 ]

Author:

{'username': 'jeff-allen-mongo', 'name': 'jeff-allen-mongo', 'email': 'jeffrey.allen@10gen.com'}

Message: (DOCS-13183): Adding bsonSize expression
Branch: master
https://github.com/mongodb/docs/commit/eab3ad8cf51e554c5322823b6039356a35f15fdf

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