您如何修改我们在创建集合时设置的选项?
在 MongoDB 3.6 中,只能在创建集合时指定默认排序规则选项。不支持修改默认排序规则选项。
但是,如果您想使用默认值以外的排序规则选项,您可以为支持排序规则collation
的操作指定一个文档,例如和。find()
aggregate()
我们如何查看已经设置的选项?
有几种方法。
shell 助手显示额外的db.getCollectionInfos()
集合信息,例如排序规则默认值:
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"
}
您还可以检查查询计划器使用的默认排序规则选项:
> 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"
}