MongoDB: Find max length of a string field in a collection

db.your_collection_name.aggregate([{ "$group":  {
    "_id" : null,
    "max" : { "$max" : { "$strLenCP" : "$your_field_name" } }
  }}
]) 

Works for modern mongos.

Leave a Reply

Your email address will not be published. Required fields are marked *