Mongo TTL utility not working

I am trying to get Mongo to delete documents using the TTL function, but to no avail. Tried a lot of things, but mongo doesn't seem like cleaning up.

My index:

    {
    "v" : 1,
    "key" : {
        "date" : 1
    },
    "name" : "date_1",
    "ns" : "history.history",
    "expireAfterSeconds" : 60
}

Date value from document:

       "date" : "2016-09-29 11:08:46.461207",

Output from db.serverStatus (). metrics.ttl:

{ "deletedDocuments" : NumberLong(0), "passes" : NumberLong(29) }

Time output from db.serverStatus ():

"localTime" : ISODate("2016-09-29T11:19:45.345Z")

The only thing I suspect is how I insert the value from Python. Maybe this is somewhat wrong. I have a JSON document that contains the following element:

"date": str(datetime.utcnow()), 

Any clues where the problem might occur?

Thank you Janis

+4
source share
1 answer

As you may have guessed, the problem is how you insert the date value. I will give docs :

, , .

. pymongo, native MongoDB .

, :

"date": datetime.utcnow()
+2

Source: https://habr.com/ru/post/1656217/


All Articles