- MongoDB官方文档中文版
 - MongoDB中文手册说明
 - MongoDB简介
 - 安装 MongoDB
 - The mongo Shell
 - MongoDB CRUD 操作
 - 聚合
 - 数据模型
 - 事务
 - 索引
 -  安全   
- 安全检查列表
 - 启用访问控制
 - 身份验证
 - 基于角色的访问控制
 - TLS / SSL(传输加密)
 - 静态加密
 - 客户端字段级加密
 - 审计
 - 网络和配置强化
 - 实现字段级别修订
 - 安全参考
 - 附录
 
 - 变更流
 - 复制
 - 分片   
- 分片键
 - 哈希分片
 - 范围分片
 - 区
 - 管理分片区
 - 按位置细分数据
 - 用于更改SLA或SLO的分层硬件
 - 按应用或客户细分数据
 - 仅插入工作负载的分布式本地写入
 - 管理分片区
 - 使用块进行数据分区
 - 在分片集群中拆分数据块
 
 - 管理
 -  存储   
-  存储引擎   
- 日志记录
 - 管理日志记录   
- GridFS
 
 
 - FAQ:MongoDB 存储
 
 -  存储引擎   
 - 参考   
- 运算符
 - 查询与映射运算符
 - 更新运算符
 - 聚合管道阶段
 -  聚合管道操作符   
- $abs (aggregation)
 - $acos (aggregation)
 - $acosh (aggregation)
 - $add (aggregation)
 - $addToSet (aggregation)
 - $allElementsTrue (aggregation)
 - $and (aggregation)
 - $anyElementTrue (aggregation)
 - $arrayElemAt (aggregation)
 - $arrayToObject (aggregation)
 - $asin (aggregation)
 - $asinh (aggregation)
 - $atan (aggregation)
 - $atan2 (aggregation)
 - $atanh (aggregation)
 - $avg (aggregation)
 - $ceil (aggregation)
 - $cmp (aggregation)
 - $concat (aggregation)
 - $concatArrays (aggregation)
 - $cond (aggregation)
 - $convert (aggregation)
 - $cos (aggregation)
 - $dateFromParts (aggregation)
 - $dateToParts (aggregation)
 - $dateFromString (aggregation)
 - $literal (aggregation)
 
 - 查询修饰符
 - 数据库命令
 - 聚合命令
 - 地理空间命令
 - 查询和写操作命令
 - 查询计划缓存命令
 - 认证命令
 - 用户管理命令
 - 角色管理命令
 - 复制命令
 - 分片命令
 - 会话命令
 - 管理命令
 - 诊断命令
 - 免费监控命令
 - 系统事件审计命令
 - mongo Shell 方法
 -  集合方法   
- db.collection.aggregate()
 - db.collection.bulkWrite()
 - db.collection.copyTo()
 - db.collection.count()
 - db.collection.countDocuments()
 - db.collection.estimatedDocumentCount()
 - db.collection.createIndex()
 - db.collection.createIndexes()
 - db.collection.dataSize()
 - db.collection.deleteOne()
 - db.collection.deleteMany()
 - db.collection.distinct()
 - db.collection.drop()
 - db.collection.dropIndex()
 - db.collection.dropIndexes()
 - db.collection.ensureIndex()
 - db.collection.explain()
 - db.collection.find()
 - db.collection.findAndModify()
 - db.collection.findOne()
 - db.collection.findOneAndDelete()
 - db.collection.findOneAndReplace()
 - db.collection.findOneAndUpdate()
 - db.collection.getIndexes()
 - db.collection.getShardDistribution()
 - db.collection.getShardVersion()
 - db.collection.insert()
 - db.collection.insertOne()
 - db.collection.insertMany()
 - db.collection.isCapped()
 - db.collection.latencyStats()
 - db.collection.mapReduce()
 - db.collection.reIndex()
 - db.collection.remove()
 - db.collection.renameCollection()
 - db.collection.replaceOne()
 - db.collection.save()
 - db.collection.stats()
 - db.collection.storageSize()
 - db.collection.totalIndexSize()
 - db.collection.totalSize()
 - db.collection.update()
 - db.collection.updateOne()
 - db.collection.updateMany()
 - db.collection.watch()
 - db.collection.validate()
 
 - 词汇表
 - 默认的MongoDB端口
 - 默认的MongoDB读/写关注
 - 服务器会话
 
 - MongoDB驱动
 - FAQ
 - 联系我们
 - 更多资料   
- [快学Mongo]
 - [Mongo问题讨论区]
 - [Mongo 驱动使用手册]
 
 - 本书使用 GitBook 发布
 
不分大小写索引
不分大小写索引
在本页面
3.4版本新功能
不区分大小写索引支持执行不考虑大小写的字符串比较的查询。
通过指定“collation”参数作为选项,可以使用' db.collection.createIndex() '创建大小写不敏感索引。例如:
db.collection.createIndex( { "key" : 1 },
                           { collation: {
                               locale : <locale>,
                               strength : <strength>
                             }
                           } )
要为区分大小写的索引指定排序规则,请包括:
- locale:指定语言规则。参见Collation locale获取可用locale列表。
 - strength:确定比较规则。值“1”或“2”表示排序规则不区分大小写。
 
有关其他排序字段,请参见collation。
行为
使用不区分大小写的索引不会影响查询的结果,但可以提高性能;请参阅Indexes以获得关于索引成本和收益的详细讨论。
若要使用指定排序规则的索引,查询和排序操作必须指定与索引相同的排序规则。如果集合定义了排序规则,所有查询和索引都会继承该排序规则,除非它们显式指定不同的排序规则。
例子
创建不区分大小写的索引
使用一个不分大小写指数在一组没有默认排序,创建一个索引排序和“strength”参数设置为“1”或“2”(见排序的strength参数的详细描述)。必须在查询级别指定相同的排序规则,才能使用索引级别的排序规则。
下面的示例创建一个没有默认排序规则的集合,然后在“type”字段上使用大小写不敏感排序规则添加索引。
db.createCollection("fruit")
db.fruit.createIndex( { type: 1},
                      { collation: { locale: 'en', strength: 2 } } )
要使用索引,查询必须指定相同的排序规则。
db.fruit.insert( [ { type: "apple" },
                   { type: "Apple" },
                   { type: "APPLE" } ] )
db.fruit.find( { type: "apple" } ) // does not use index, finds one result
db.fruit.find( { type: "apple" } ).collation( { locale: 'en', strength: 2 } )
// uses the index, finds three results
db.fruit.find( { type: "apple" } ).collation( { locale: 'en', strength: 1 } )
// does not use the index, finds three results
具有默认排序规则的集合中的区分大小写的索引
使用默认排序规则创建集合时,除非指定不同的排序规则,否则随后创建的所有索引都会继承该排序规则。所有没有指定不同排序规则的查询也继承默认排序规则。
下面的示例使用默认排序规则创建名为“names”的集合,然后在“first_name”字段上创建索引。
db.createCollection("names", { collation: { locale: 'en_US', strength: 2 } } )
db.names.createIndex( { first_name: 1 } ) // inherits the default collation
插入少量名称:
db.names.insert( [ { first_name: "Betsy" },
                   { first_name: "BETSY"},
                   { first_name: "betsy"} ] )
对该集合的查询默认情况下使用指定的排序规则,如果可能还使用索引。
db.names.find( { first_name: "betsy" } )
// inherits the default collation: { collation: { locale: 'en_US', strength: 2 } }
// finds three results
上述操作使用集合的默认排序规则并查找所有三个文档。它使用' first_name '字段上的索引以获得更好的性能。
通过在查询中指定不同的排序规则,仍然可以对这个集合执行区分大小写的搜索:
db.names.find( { first_name: "betsy" } ).collation( { locale: 'en_US' } )
// does not use the collection's default collation, finds one result
上面的操作只找到一个文档,因为它使用的排序规则没有指定strength值。它不使用集合的默认排序规则或索引。
Copyright © 上海锦木信息技术有限公司 all right reserved,由 MongoDB汉化小组 提供技术支持文件修订时间: 2020-10-11 20:53:05
