操作失败不支持投影选项:endingDate

2024-09-28 22:27:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图获取endingDate大于或等于currentDateTime的文档,并获取entityID

    {"_id":{"$oid":"5ecfba0b1191f2b87ee1ccd2"},
    "entityId":"5ecfb9d9d654557162afd861",
    "endingDate":{"$date":"2020-08-11T00:00:00.000Z"}

我的问题是:

cursor= list(db.collection.find({},{"entityId":1,
"endingDate":{"$gte":datetime.datetime.now().isoformat()}}))

但这给了我错误

OperationFailure: Unsupported projection option: endingDate: { $gte: "2020-08-11T19:28:06.677643" }

编辑1: 我也试过这个问题

import datetime
from datetime import datetime
temp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
date_time_obj = datetime.strptime(temp, '%Y-%m-%d %H:%M:%S')

cursor=list(db.TrendAnalysisSystem_jobdata.find({},
            {"entityId":1,"hashTags":1,"skillsRequired":1,
             "specialization":1,"endingDate":{"$gte":date_time_obj}}))

仍然得到相同的错误


Tags: importobjdbdatetimedatetime错误find