在mongodb中选择字符串长度 [英] Select string length in mongodb
问题描述
如何查询mongodb以查找特定字符串/文本字段的长度?
How do you query mongodb to find the length of a particular string/text field?
您将如何找到查询集的最大长度?
And how would you find the max length of a query set?
推荐答案
不幸的是,聚合框架不支持在执行查询时将字符串自动转换为长度的"len"运算符.因此,您必须在自己的代码中解决此问题.你可以
Unfortunately the aggregation framework doesn't support a "len" operator to automatically convert strings to their length while you do a query. So you have to solve this in your own code. You could
- 使用MapReduce函数计算字符串长度
- 查询字符串并计算其在应用程序层上的长度
这两种方法之间的区别在于,第一种方法在数据库上运行,而第二种方法在应用程序服务器上运行.我建议使用后一种方法,因为MapReduce使用起来很慢而且很麻烦.
The difference between these method is that the first runs on the database while the latter runs on your application server. I would recommend the latter option, because MapReduce can be very slow and cumbersome to use.
这篇关于在mongodb中选择字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!