Flask-PyMongo collMod
Flask-PyMongo collMod
我正在尝试使用 PyMongo 更新 TTL 集合。尝试 运行 这个我得到 'failed no such cmd: index'
client.db.command({'collMod': url,
'index': {'keyPattern': {'dateCreated':1},
'expireAfterSeconds': 3600}})
有人指出我做错了什么吗?
好吧,我刚刚决定改变我的索引,而不是设置我希望文档在数据库中过期的时间,而不是通过使用
来说明我希望文档存在多长时间
db.test.ensure_index("expireOn", expireAfterSeconds=0)
现在我可以将该字段设置为我希望条目过期的未来时间,而不必更改索引。 似乎很奇怪,到目前为止还没有办法使用 python.
以编程方式更新索引
我相信这会起作用,假设 url
包含带有您正在修改的索引的集合的名称:
client.db.command('collMod', url,
index={'keyPattern': {'dateCreated':1},
'expireAfterSeconds': 3600}})
对于寻找解决方案的其他人,我使用以下方法进行了管理:
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}
我正在尝试使用 PyMongo 更新 TTL 集合。尝试 运行 这个我得到 'failed no such cmd: index'
client.db.command({'collMod': url,
'index': {'keyPattern': {'dateCreated':1},
'expireAfterSeconds': 3600}})
有人指出我做错了什么吗?
好吧,我刚刚决定改变我的索引,而不是设置我希望文档在数据库中过期的时间,而不是通过使用
来说明我希望文档存在多长时间db.test.ensure_index("expireOn", expireAfterSeconds=0)
现在我可以将该字段设置为我希望条目过期的未来时间,而不必更改索引。 似乎很奇怪,到目前为止还没有办法使用 python.
我相信这会起作用,假设 url
包含带有您正在修改的索引的集合的名称:
client.db.command('collMod', url,
index={'keyPattern': {'dateCreated':1},
'expireAfterSeconds': 3600}})
对于寻找解决方案的其他人,我使用以下方法进行了管理:
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}