pymongo multi-condition filter time error'module' object is not callable

During the recent data analysis of resignation personnel, I found that when selecting the data set for resignation time and entry time at the same time, errors occurred frequently, as follows:
Insert picture description here

Just add **{"company.hiredate":{"$lt":datetime(2020,1,1,0,0,0,0)}}** conditions to filter and an error will be reported. If you switch to other fields, you won't (as shown in the figure below). I thought that my code was written incorrectly. I checked carefully and there were no logical or grammatical errors.
Insert picture description here

When inquiring about the date of resignation, it was pitted , because the MongoDB data storage format is Date (253402300799999) , when inquiring, you cannot use the ISODate ("2011-03-15T06:36:36.000Z") time type query method. For example, if you want to query the resignation time as ISODate("9999-12-31T23:59:59.999Z") , that is, the personnel in the in-service status, what should I do?
A clever method is adopted. Since you are employed, the resignation date must not be greater than the current time + 1, first get the current time today, and then add 1 day on this basis, as a variable re_date in the query time filter condition.
import datetime
today=datetime.datetime.now()#The time of the day
offset = datetime.timedelta(days=+1)
#Add a day re_date = today + offset

As a result, guess whether company.hiredate may also have such a problem. Going back to MongoDB and found that it is true, the data format of this field is not uniform

Insert picture description here

Therefore, it is handled in the same way. Since it is necessary to find the employees who joined the company before December 31, 2019 but did not leave, if the variable start=datetime.datetime(2020,1, 1, 0, 0, 0 is filtered according to the set time , 0), take the personnel less than this entry time, and modify the code to
Insert picture description here

Only two query results are shown here, which means that the problem is solved.

Insert picture description here

Guess you like

Origin blog.csdn.net/zxxxlh123/article/details/108747680