MongoDB 高级索引
高级索引能力:索引内嵌字段(doc.field)、数组字段索引、稀疏索引、TTL 索引(自动过期)、通配符索引。
Key PointsMongoDB,内嵌索引,TTL 索引,稀疏索引,通配符索引
讲解
高级索引能力:索引内嵌字段(doc.field)、数组字段索引、稀疏索引、TTL 索引(自动过期)、通配符索引。
示例
JavaScript
db.users.createIndex({ "addr.city": 1 }) // 内嵌字段
db.users.createIndex({ tags: 1 }) // 数组多键索引
db.logs.createIndex({ at: 1 }, { expireAfterSeconds: 3600 }) // TTL
db.users.createIndex({ "$**": 1 }) // 通配符讲解
高级索引能力:索引内嵌字段(doc.field)、数组字段索引、稀疏索引、TTL 索引(自动过期)、通配符索引。
示例
JavaScript
db.users.createIndex({ "addr.city": 1 }) // 内嵌字段
db.users.createIndex({ tags: 1 }) // 数组多键索引
db.logs.createIndex({ at: 1 }, { expireAfterSeconds: 3600 }) // TTL
db.users.createIndex({ "$**": 1 }) // 通配符