Hey Everyone,
In my collection there is field called as time and the format of this field is as follows :
time: “2019/05/02 00:00:00”.
I need to extract hours from this field and group them based on hour. I tried many things including ISODate(), new Date() but getting different errors. Below is my project block followed by one of the errors. Any help in this regard will be appreciated.
command_2 = {"$project": {"_id": 0,
"station_id": 1,
"station_status": 1,
"hour": {"$hour": "$time"},
"available_bikes": 1
}
}
my_query.append(command_2)
pymongo.errors.OperationFailure: can’t convert from BSON type string to Date, full error: {‘operationTime’: Timestamp(1616064173, 4), ‘ok’: 0.0, ‘errmsg’: “can’t convert from BSON type string to Date”, ‘code’: 16006, ‘codeName’: ‘Location16006’, ‘$clusterTime’: {‘clusterTime’: Timestamp(1616064173, 4), ‘signature’: {‘hash’: b’\xe0\xdd\x7f\xd6&\x1d\r\xb5\xdfv\x11\xc3\x88\xfc\xb1L\x93\x7f\xb8\xe1’, ‘keyId’: 6929970731853807619}}}