0
db.temp.ensure_index("createdAt",expireAfterSeconds=3*60)
timestamp = datetime.utcnow()
for i in l:
    i["createdAt"] = timestamp
    i['table'] = 1
    db.temp.insert_one(i)

在上面的代码中,expireAfterSeconds只有指定为3*60. 如果我改变它的值,我会得到错误。我需要将过期时间设置为10分钟

错误:引发 OperationFailure(errmsg, code, response, max_wire_version) pymongo.errors.OperationFailure: Index with name: createdAt_1 already exists with different options, full error: {'operationTime': Timestamp(1632732176, 1), 'ok': 0.0 , 'errmsg': 'Index with name: createdAt_1 already exists with different options', 'code': 85, 'codeName': 'IndexOptionsConflict', '$clusterTime': {'clusterTime': Timestamp(1632732176, 1), '签名': {'hash': b"\xb4\xaf\xaa\xb7\x1e\xd4:\xa4\xf7\x81\xa8\xa9\xef\xa1}\xa7\x8e('i", 'keyId' : 6961454804933541890}}}

4

0 回答 0