[SERVER-30967] Add $binarySize expression Created: 06/Sep/17  Updated: 30/Oct/23  Resolved: 21/Nov/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 4.3.3

Type: New Feature Priority: Major - P3
Reporter: Stephen Tunney (Inactive) Assignee: David Percy
Resolution: Fixed Votes: 1
Labels: expression, neweng, pm1457
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Documented
is documented by DOCS-13185 Investigate changes in SERVER-30967: ... Closed
Related
related to SERVER-33582 Add $bsonSize expression Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2019-12-02
Participants:
Case:

 Description   

The query team has discussed and decided on the following syntax/semantics:

Name: $binarySize

Alternate Names: $binSize, $byteSize

This expression takes an expression that evaluates to a string or BinData and return the size of the value in bytes. It will error if the result evaluates to a type other than string, BinData, or null. Given nullish, returns null.
Syntax:

{ $binarySize: <Expression> }

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

Original Description

Implement an aggregation expression that return the length of BinData type value.

This would work much in the same way as SERVER-14670

Examples
Input

db.coll.insert({_id: 0, bin: new BinData(3, "OEJTfmD8twzaj/LPKLIVkA==")})

Pipeline

db.coll.aggregate([{
    $project: {
        "BinLength": {$binLenBytes: "$bin"}
    }
}])

Output

{_id: 0, BinLength: 16}



 Comments   
Comment by Githook User [ 21/Nov/19 ]

Author:

{'email': 'david.percy@mongodb.com', 'name': 'David Percy', 'username': 'dpercy'}

Message: SERVER-30967 Add $binarySize expression
Branch: master
https://github.com/mongodb/mongo/commit/95c3c98350352fb4fe069a33efa478f3eb88eefc

Comment by Githook User [ 21/Nov/19 ]

Author:

{'name': 'David Percy', 'username': 'dpercy', 'email': 'david.percy@mongodb.com'}

Message: SERVER-30967 Add $binarySize expression
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/cbb834ac6348c048d599b7f748b8ec4922c2b307

Comment by Asya Kamsky [ 07/Apr/18 ]

Is there a reason to restrict this expression to work on Binary only? If it also worked on strings we could remove $strLenBytes and simplify how many functions return length of string/stream things in bytes. (and we could then alias $strLenCP to $strLen).

It could be named $byteLen or $lenBytes.

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