Following is the aggregation query -

result = list( self._collection.aggregate( [ {“$match”: {“schemaId”: {“$in”: schema_ids}}}, {“$sort”: {“createdOn”: -1}}, {“$limit”: 1}, {“$project”: {“_id”: 1}}, ] ) )