0

I am trying to get the document whose endingDate is greater or equal to currentDateTime and also fetching entityID.

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

My query is:

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

But it giving me error.

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

Edit 1: I tried this query also

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}}))

still getting the same error

NoobCoder
  • 625
  • 1
  • 5
  • 18
  • This may help [How to make a query date in mongodb using pymongo?](https://stackoverflow.com/questions/26366417/how-to-make-a-query-date-in-mongodb-using-pymongo) – ambianBeing Aug 11 '20 at 15:20

1 Answers1

1

You put the find condition into the projection argument. Try:

  cursor= list(db.collection.find({"endingDate":        {"$gte":datetime.datetime.now().isoformat()}},{"entityId":1,    }))
D. SM
  • 13,584
  • 3
  • 12
  • 21