Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
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
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:
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" : [
],
"ok" : 1.0000000000000000
}