【问题标题】:OperationFailure Unsupported projection option: endingDateOperationFailure 不支持的投影选项:endingDate
【发布时间】:2020-12-01 05:06:54
【问题描述】:

我正在尝试获取其 endDate 大于或等于 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}}))

还是出现同样的错误

【问题讨论】:

标签: python mongodb mongodb-query


【解决方案1】:

您将查找条件放入投影参数中。试试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多