如何查看或修改在 MongoDB 集合上设置的排序规则选项? [英] How to view or modify collation options set on a MongoDB collection?
问题描述
您如何修改我们在创建时为集合设置的选项?我们如何查看已设置的选项?
How do you modify the options that we set on a collection at the time of creation? And how do we view the options already set?
例如,如果我们看到整理选项,我会创建一个这样的集合:
If we see the collation option for example, I create a collection like this:
db.createCollection("words", {collation : {locale :"es", strength : 2}});
并添加几个文件:
db.words.insertOne({text : "Résumé"});
db.words.insertOne({text : "Resume"});
db.words.insertOne({text : "résumé"});
db.words.insertOne({text : "resume"});
如何将这个集合的排序规则的强度更改为 3?我怎么看变化?我在 db
对象或 db.words
对象或文档中没有看到任何可用的相关函数!
How do I change the strength of the collation on this collection to 3? how do I see the change? I do not see any relevant functions available on the db
object or db.words
object or in the docs!
推荐答案
您如何修改我们在创建时为集合设置的选项?
How do you modify the options that we set on a collection at the time of creation?
在 MongoDB 3.6 中,只能在创建集合时指定默认排序规则选项.不支持修改默认排序规则选项.
As at MongoDB 3.6, the default collation options can only be specified when a collection is created. There is no support for modifying the default collation options.
但是,如果您想使用除默认值以外的排序规则选项,您可以为 支持排序的操作,例如find()
和aggregate()
.
However, if you want to use collation options other than the default you can specify a collation
document for operations that support collation, such as find()
and aggregate()
.
我们如何查看已设置的选项?
how do we view the options already set?
有几种方法.
db.getCollectionInfos()
shell helper 显示额外的集合信息,例如排序规则默认值:
The db.getCollectionInfos()
shell helper displays additional collection information such as collation defaults:
db.getCollectionInfos({name:'words'})[0].options.collation
{
"locale": "es",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
}
您还可以检查查询计划器使用的默认排序规则选项:
You can also check the default collation options used by the query planner:
> db.words.find().explain().queryPlanner.collation
{
"locale": "es",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
}
这篇关于如何查看或修改在 MongoDB 集合上设置的排序规则选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!