mongodb 索引日常维护操作步骤
发布时间:2023-10-06 15:13:22 所属栏目:系统 来源:
导读:创建索引:
db.t_order_detail.createIndex({"order_id":1})
复合索引:
db.t_order_detail.createIndex({"order_id":1,"detail_id":1,"batch_id":1})
在后台创建索引:
db.t_order_detail.crea
db.t_order_detail.createIndex({"order_id":1})
复合索引:
db.t_order_detail.createIndex({"order_id":1,"detail_id":1,"batch_id":1})
在后台创建索引:
db.t_order_detail.crea
创建索引: db.t_order_detail.createIndex({"order_id":1}) 复合索引: db.t_order_detail.createIndex({"order_id":1,"detail_id":1,"batch_id":1}) 在后台创建索引: db.t_order_detail.createIndex({order_id:1},{background:1}) 创建TTL索引: a.经过指定的时间间隔后,集合失效: db.t_order_detail.createIndex( { "createTime": 1 }, { expireAfterSeconds: 60*60 } ) -----过期时间(单位秒) 使用getIndexes() 查看 修改TTL索引的expireAfterSeconds属性值: db.runCommand( { collMod: "t_order_detail",index: { keyPattern: { createTime: 1 },expireAfterSeconds: 7200}}) b.指定时间点过期,集合失效: db.t_order_detail.createIndex({"expireAt": 1},{expireAfterSeconds:0}) db.t_order_detail.insert({ "createdAt": new Date('Oct 21, 2018 21:30:00'), "log_Event": 1, "log_Message": "Success!" }) 查看索引: db.t_order_detail.getIndexes() 查看索引键: db.t_order_detail.getIndexKeys() 查看集合索引总大小: db.t_order_detail.totalIndexSize() 查看集合各索引的详细信息: db.t_order_detail.getIndexSpecs() 删除索引: db.t_order_detail.dropIndex("index_name") 删除所有索引 db.t_order_detail.dropIndexes()方法用于删除全部的索引 索引重建: db.t_order_detail.reIndex({"order_id":1}) (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐