On this page本页内容
cursor.
collation
(<collation document>)¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
New in version 3.4.版本3.4中的新功能。
Specifies the collation for the cursor returned by the 指定db.collection.find()
. db.collection.find()
返回的游标的排序规则。To use, append to the 要使用,请附加到db.collection.find()
.db.collection.find()
。
The cursor.collation()
accepts the following collation document:cursor.collation()
接受以下排序规则文档:
When specifying collation, the 指定排序规则时,locale
field is mandatory; all other collation fields are optional. locale
字段是必需的;所有其他排序规则字段都是可选的。For descriptions of the fields, see Collation Document.有关这些字段的描述,请参阅排序规则文档。
locale |
string | The ICU locale. See Supported Languages and Locales for a list of supported locales. To specify simple binary comparison, specify | ||||||||||||
strength |
integer |
See ICU Collation: Comparison Levels for details. | ||||||||||||
caseLevel |
boolean |
If
For more information, see ICU Collation: Case Level. | ||||||||||||
caseFirst |
string |
| ||||||||||||
numericOrdering |
boolean |
If If Default is | ||||||||||||
alternate |
string |
See ICU Collation: Comparison Levels for more information. Default is | ||||||||||||
maxVariable |
string |
Possible values are:
| ||||||||||||
backwards |
boolean |
| ||||||||||||
normalization |
boolean |
See http://userguide.icu-project.org/collation/concepts#TOC-Normalization for details. |
Consider a collection 使用以下文档来考虑foo
with the following documents:foo
集合:
The following operation specifies a query filter of x: "a"
. The operation also includes a collation option with locale: "en_US"
(US English locale) and strength: 1
(compare base characters only; i.e. ignore case and diacritics):
The operation returns the following documents:该操作将返回以下文档:
If you do not specify the collation, i.e. 如果不指定排序规则,即db.collection.find( { x: "a" } )
, the query would only match the following document:db.collection.find( { x: "a" } )
,则查询将只匹配以下文档:
You can chain other cursor methods, such as cursor.sort()
and cursor.count()
, to cursor.collation()
:
Note
You cannot specify multiple collations for an operation. 不能为一个操作指定多个排序规则。For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort.例如,不能为每个字段指定不同的排序规则,或者如果使用排序执行查找,则不能对查找使用一种排序规则,对排序使用另一种排序规则。