To make the question more clear, here are the steps and context:
I am trying to check which collections have changes to retry by timer after a recent failure case to prevent unnecessary wait. Somehow the comparison using the clusterTime from previous change to record change dates doesn’t work well. Before I add the isoformat() conversion, different dates work fine while same date with only difference in time failed and I found " " instead of “Z” in the converted clusterTime and so I added isoformat() to get “Z” added in, it fixes the issue of same date with only time difference. However, looks like different dates stopped working which is very strange since the convert string format and the DB query of 2 date fields to be compared all look correct with “T” though I don’t see the “Z” in the end of the string.
- Get last change timestamp
Get the clusterTime from latest MongoDB change stream event which is Timestamp or BSON Timestamp format
src_last_change_time = self.get_src_last_change_time(collection_name)
-
Convert Timestamp to ISO Date
src_last_change_date = datetime.fromtimestamp(src_last_change_time.time, tz=timezone.utc).isoformat()
-
Check any changes in the collection after above ISO date
`change_collection = self.db[collection_name]
count = change_collection.count_documents(
{“$or”: [{‘first_deployment_date’: {‘$exists’: True, ‘$gt’: src_last_change_date}},
{‘document_last_change_date’: {‘$exists’: True, ‘$gt’: src_last_change_date}}]}, limit=1)
return count > 0
`
Not sure I have missed anything basic, but it really feels like strange.
Thank you!