mongodb ttl索引
2021/9/14 2:04:48
本文主要是介绍mongodb ttl索引,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
mongodb ttl索引
作用
所有可以通过指定data类型的数据值进行自动删除所谓的过期数据
创建索引
创建索引 collection 集合名 createTime 字段名,且类型为data expireAfterSeconds 过期时间,单位是秒 db.collection.createIndex({"createTime":1},{expireAfterSeconds:6})
Demo
修改索引
collection 集合名 createTime ttl 索引字段 类型为data expireAfterSeconds 过期时间,单位是秒 db.runCommand({ collMod: "collection", index: { keyPattern: { createTime: 1 },expireAfterSeconds: 7}})
Demo
查看索引
collection 集合名 db.collection.getIndexes()
Demo
删除索引
db.collection.dropIndex("索引名")
Demo
这篇关于mongodb ttl索引的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26解决google chrome helper 内存占用较高!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb