Flask-PyMongo collMod

前端 未结 2 992
北海茫月
北海茫月 2021-01-25 06:37

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,
                     


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 07:11

    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})
    

    Which results in the following output:

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

提交回复
热议问题