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