mongoDb增加索引,过期对象的两种方式

通过设置TTL使集合中的数据过期

1,在特定的时间过期文档 (根据expireAt 字段的时间值进行过期)
db.ediInterfaceDocment.createIndex({"expireAt":1},{ expireAfterSeconds: 0 })
2,添加单升序索引
db.getCollection('interfaceLogDocment').createIndex( { "msgSubjectVice": 1 } )
3,添加复合升序索引
db.getCollection('interfaceLogDocment').createIndex( { "item": 1, "stock": 1 })
4,查询有哪些索引存在
db.collection.getIndexes()

算了,不写了,看mongoDb中文社区文档吧

MongoDB中文手册|官方文档中文版

posted @ 2021-04-21 13:22  darling331  阅读(207)  评论(0编辑  收藏  举报