本文介绍了Flask-PyMongo collMod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyMongo 更新 TTL 集合.试图运行这个我得到没有这样的 cmd: index 失败"

I'm trying to update a TTL collection with the PyMongo. Trying to run this I get 'failed no such cmd: index'

client.db.command({'collMod': url,
                    'index': {'keyPattern': {'dateCreated':1},
                           'expireAfterSeconds': 3600}})

有人指出我做错了什么吗?

anyone shine some light on what I'm doing wrong?

推荐答案

我相信假设 url 包含您正在修改的索引的集合的名称:

I believe that this would work assuming that url contains the name of the collection with the index you are modifying:

client.db.command('collMod', url,
                  index={'keyPattern': {'dateCreated':1},
                         'expireAfterSeconds': 3600}})

对于其他正在寻找解决方案的人,我使用以下方法进行了管理:

For anyone else looking for a solution to this I managed with the following:

client.db.command('collMod', 'notifications', 
                  index={'keyPattern': {'expr': 1}, 
                         'background': True, 
                         'expireAfterSeconds': 604800})

结果如下:

{u'expireAfterSeconds_old': 3888000, 
 u'expireAfterSeconds_new': 604800, u'ok': 1.0}

这篇关于Flask-PyMongo collMod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 08:33