[DOCS-10660] Comment on: "manual/reference/operator/aggregation/size" Created: 09/Aug/17  Updated: 30/Oct/23  Resolved: 13/Dec/18

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

Type: Bug Priority: Major - P3
Reporter: Amy Aldredge Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, mongo version 3.4.2

Location: https://docs.mongodb.com/manual/reference/operator/aggregation/size/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0
Screen Resolution: 1536 x 864


Participants:
Days since reply: 5 years, 8 weeks, 6 days ago
Epic Link: DOCSP-1769

 Description   

The example skips a very important caveat: All documents must have the list, otherwise there should be a match step before the size.

example
test collection:

{ "_id" : 1, "myArray" : [ 1, 2 ], "myStr" : "sfsaf"} { "_id" : 2, "myStr" : "asdf"}

aggregation pipeline:
db.getCollection('test').aggregate([{$project:{_id:1, "arraySize":{$size:"$myArray"}}}])

error: uncaught exception: aggregate failed:

{ "ok" : 0, "errmsg" : "The argument to $size must be an array, but was of type: missing", "code" : 17124, "codeName" : "Location17124" }

pipeline with match added:
db.getCollection('test').aggregate([{$match:{myArray:{$exists:true}}},{$project:{_id:1, "arraySize":{$size:"$myArray"}}}])

result:
{
"result" : [

{ "_id" : ObjectId("598b464d4fa2cd261a1cc433"), "arraySize" : 2 }

],
"ok" : 1.0000000000000000
}



 Comments   
Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'kay-kim', 'email': 'kay.kim@10gen.com', 'name': 'kay'}

Message: DOCS-10660: update $size example to check if array
Branch: v3.2
https://github.com/mongodb/docs/commit/0930773627789c7cebe3dd2c73fe58afc547ff6c

Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'kay-kim', 'email': 'kay.kim@10gen.com', 'name': 'kay'}

Message: DOCS-10660: update $size example to check if array
Branch: v3.4
https://github.com/mongodb/docs/commit/109b188dc1ebc92aadb42a44bb18cbfef977c8f4

Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'kay-kim', 'email': 'kay.kim@10gen.com', 'name': 'kay'}

Message: DOCS-10660: update $size example to check if array
Branch: v3.6
https://github.com/mongodb/docs/commit/b53d397c16addd1b8794cbd676c90f75b4d0af35

Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'kay-kim', 'email': 'kay.kim@10gen.com', 'name': 'kay'}

Message: DOCS-10660: update $size example to check if array
Branch: v4.0
https://github.com/mongodb/docs/commit/785584909216b60876635c2a09dec2be979e4dcf

Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'kay-kim', 'email': 'kay.kim@10gen.com', 'name': 'kay'}

Message: DOCS-10660: update $size example to check if array
Branch: master
https://github.com/mongodb/docs/commit/fa3c2a7edc4488afd4dac75743ecf6e20a8e6e57

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