Use aggregation, db. Collection name. Aggregate... Rather than find.
Pipelines are typically used in UNIX and Linux to use the output of the current command as a parameter to the next command.
MongoDB's aggregation pipeline passes the MongoDB document to the next pipeline processing after a pipeline has finished processing. Pipeline operations can be repeated.
Each operator (the collection) takes a series of documents, makes some type conversions on those documents, and finally passes the converted document as a result to the next operator, and for the last operator, returns the result to the client
Grouping (the field name of the Group field $+ is established here)
As you can see here, Lastmodifybyusercode as a unique identifier _id, the field count calculates the number of occurrences of the same lastmodifybyusercode with $sum
Db.test.aggregate ({' $group ': {' _id ': ' $lastModifyByUserCode ', ' count ': {' $sum ': 1}}})
Show additional fields (must use aggregation [$sum, $avg, $first, $last, $max, $min, $push, $addToSet, $stdDevPop, $stdDevSamp])
Db.test.aggregate ({' $group ': {' _id ': ' $lastModifyByUserCode ', ' count ': {' $sum ': 1}, ' Createtime ': {' $first ': ' $ Createtime "}}})
$match is used to filter the collection of documents, supports find-like filters, cannot use geospatial operators in $match, (as far as possible to put $match in the first of multiple aggregations, so that the index can be effectively used)
And according to official documentation, if full-text indexing is used in $match, then the aggregations that follow are no longer used $text
MongoDB, grouping, aggregation