1
A
回答
2
你应该使用$substrCP
,而不是$substr
。 $substrCP
MongoDB中3.4引入来解决这样的问题,因为$substr
从MongoDB的文档,只为ASCII字符
工作:
$substrCP
Returns the substring of a string. The substring starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string for the number of code points specified.
所以你的查询是:
db.carte.aggregate([
{$project: {
preview: {$substrCP: ["$titlu", 0, 1]}
}
}
])
相关问题
- 1. mongodb 3.4.2 InvalidIndexSpecificationOption错误:字段'unique'对于_id索引规范无效
- 2. Python - 索引错误:字符串索引超出范围
- 3. 索引错误:字符串索引超出范围python
- 4. 索引错误:字符串索引超出范围 -
- 5. 无效的范围错误
- 6. 错误[]无效的范围
- 7. Java中的字符串索引超出范围错误(字符串索引超出范围异常)
- 8. 怪“字符串索引超出范围:0”的错误
- 9. Python的错误:“字符串索引超出范围”
- 10. ColdFusion的“字符串索引超出范围”错误与argumentcollection
- 11. 错误与我的代码?字符串索引超出范围?
- 12. 索引错误:字符串超出范围,但它不应超出范围?
- 13. 字符串索引超出范围:7错误
- 14. Java - 字符串索引超出范围错误
- 15. ColdFusion错误 - 字符串索引超出范围:0
- 16. Python函数错误字符串索引超出范围
- 17. 嵌入式错误:字符串索引超出范围:70
- 18. 错误:字符串索引超出范围
- 19. Java错误java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0
- 20. 字符串索引超出范围错误:如何解决?
- 21. 字符串索引超出范围错误for循环
- 22. Python错误:“IndexError:字符串索引超出范围”
- 23. Python字符串索引超出范围错误?
- 24. 凯撒密码错误:字符串索引超出范围
- 25. java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-23错误
- 26. 列表索引超出范围错误,对于包含字符串的列表
- 27. XML字符串索引超出范围
- 28. java:字符串索引超出范围
- 29. 字符串索引超出范围
- 30. 字符串索引超出范围 - Python
非常棒,谢谢!用S结果分组Ş任何方式?或者也许是一种自定义排序,以便字母顺序为A,Ă,Î,B ... I,Î,... S,Ş等等? – hypercube
查看[**排序规则**](https://docs.mongodb.com/manual/reference/collation/):在您的汇总查询中指定与第一级的排序规则 – felix
这并不重要,我可以随时使用java方面进一步定购/分组。 – hypercube