-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.6.4
-
Component/s: Querying
-
None
Hi,
I've a document which contains an array of nested object.
I need to have the global sum of the size of array.
I've written an agrgegation:
db.values.aggregate( [ {$group : { _id : null , count : { $sum: {$size : '$markers'} } } } ])
My collection contains 2610537 documents, so the query is very long. (Too long for me)
I think it will be quicker to have an intermadiate field with the markers size. But I cannot write the update query:
db.values.update( { 'sample' : 1753068}, // Used to reduce documents and test. { '$set': { 'count': { $size : markers} } }, { upsert : false } )
This give me this error:
ReferenceError: markers is not defined (shell):5
But 'markers' is my arrays of nested objects. so this field exist.
After reading the doc, $size is not part of update operators...
Is there a way to handle this case? (I know , I can do this on update or insert process)
Thanks
Mickael
- duplicates
-
SERVER-11345 Allow update to compute expressions using referenced fields like Aggregation Framework's $project
- Closed