问题
I'm currently using mongo 3.0v. I've a requirement to find the length of each string in the result from aggregate command. For eg:
db.getCollection('temp').find()
[
{"key": "value1"},
{"key": "value2" },
{"key": "valuee2"}
]
This query gives length of key field
db.getCollection('temp').aggregate([{
$project: {
"strLength": {"$strLenCP": "$key"}
}
}])
like
[
{"strLength": 6},
{"strLength": 6},
{"strLength": 7}
]
But "$strLenCP" key is not supported in prior 3.4 versions. So is there any alternate options for this?
来源:https://stackoverflow.com/questions/51040884/alternate-to-strlencp-field-in-mongodb-3-0prior-versions