alternate to $strLenCP field in mongoDB 3.0[prior versions]

此生再无相见时 提交于 2019-12-12 17:00:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!