Skip to content

Instantly share code, notes, and snippets.

@seozed
Last active May 21, 2020 10:32
Show Gist options
  • Save seozed/8d59e4850e63f8eb69a7af81c113f05a to your computer and use it in GitHub Desktop.
Save seozed/8d59e4850e63f8eb69a7af81c113f05a to your computer and use it in GitHub Desktop.
mongo 统计字段的长度并汇总
db.getCollection("mastersportal_counrse").aggregate([
{
"$project": {
"overview": {
"$strLenCP": "$overview"
},
"about": {
"$strLenCP": "$about"
}
}
},
{
$group: {
_id: null,
totalAmount: {
$sum: {
$add: ["$overview", "$about"]
}
}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment