I have records in a collection with single record like this:`` rau_record = { "_id" : ObjectId("646fdefa2601c85dd7092337"), "BOX-SN" : "3-6213905", "RAUs" : [ { "contents" : "some content", "date" : datetime.strptime("2024-01-15T22:19:38.679", "%Y-%m-%dT%H:%M:%S.%f") }, { "contents" : "...", "date" : datetime.strptime("2024-01-26T23:00:33.802", "%Y-%m-%dT%H:%M:%S.%f") } ] }
I am trying to find out whether any record in the collection having the ordered RAUs array’s last item’s date after a known date.
I have tried follow 2 methods, but neither works. Can someone help? Thank you very much!
``query = {‘$expr’: {‘$gte’: [{‘$arrayElemAt’: [“$RAUs.date”, -1]}, src_last_change_date]}}
query = {‘RAUs.date’: {‘$gte’: src_last_change_date}}, {‘RAUs’: {‘$slice’: -1}}
count = change_collection.count_documents(query, limit=1)
return count > 0
`