在Mongodb聚合管道中可以使用$strLenCP+$gt来完成此功能,如:
`{“_id”: ObjectId(“5821757bf28fbb3e3516eeaa”), “memid” : “f5869354”, “orderno” : “s00023″,”productno”:”20206539″, “comment”:”这个平底锅太好用了,性价比高”,”telephone” :”18385669845″}
{“_id”: ObjectId(“5821776ff28fbb3e3516eeab”), “memid” : “daisy”, “orderno” : “s04567”, “productno”:”20225699″,”address”:”comment”,”衣服穿起来很舒服好评” :”18855448645″}
{“_id”: ObjectId(“5821829ef28fbb3e3516eeac”), “memid” : “lucy”, “orderno” : “s08795”, “productno”:”20256339″,”address”:”comment”,”还行” :”13869669585″}
{“_id”: ObjectId(“582182b0f28fbb3e3516eead”), “memid” : “c5633256”, “orderno” : “s45689″,”productno”:”20285639″,”address”:”comment”,”不好用,不建议买” :”13699869588″}
`
`db.orderdetail.aggregate(
[
{
$project: {
“_id”:0,
“orderno”: 1,
“productno”:1,
“comlength”: { $strLenCP: “$comment” }
}
}
]
)
{“orderno” : “s00023”, “productno”:”20206539″, “comlength”:14}
{“orderno” : “s04567”, “productno”:”20225699″, “comlength”:10}
{“orderno” : “s08795”, “productno”:”20256339″, “comlength”:2}
{“orderno” : “s45689”, “productno”:”20285639″, “comlength”:8}
`
我之前写过的一个功能介绍,具体步骤可参考:
http://forum.foxera.com/mongodb/topic/1609/mongodb-strlencp%E7%9A%84%E4%BD%BF%E7%94%A8