Using Community MongoDB 4.4.3, I have a sample test collection:
client = pymongo.MongoClient('localhost', 27017)
db = client.test
collection = db.test_collection
print(collection.find_one())
>>> {'_id': ObjectId('600d8e2f4cf39c04cdb86ea0'),
'id': '0706.1314',
'update_date': '2008-12-18'}
I'm trying to convert string to date for the field update_date
with $toDate operator:
collection.aggregate([{"$toDate": "update_date"}])
But get the following error:
OperationFailure: Unrecognized pipeline stage name: '$toDate', full error: {'ok': 0.0, 'errmsg': "Unrecognized pipeline stage name: '$toDate'", 'code': 40324, 'codeName': 'Location40324'}
Why does this happen?
question from:
https://stackoverflow.com/questions/65873085/convert-string-to-date-in-pymongo 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…