Given a MongoDB collection of documents which contains an array of whatever, would be nice to can sort the documents by the length of its array.
I saw it could be reached using aggregation or an additional field which stores array length.
I'm working on a kind of QueryBuilder which doesn't use aggregation, so I've choosen to add another field.
So I need a migration script to updates all documents of the collection in order to add a field with the length of the array of each document.
This update can be realized with one update operation over all collections? How?
I tried aggregation for that, and I get the length of each array of each document, but I don't know how to use to update documents.


