When using sort, it might be good to use the pymongo.ASCENDING constant instead of 1 directly. Also, is there a reason we are sorting the collection this way? Are we trying to get the newest ones to appear last? Is that also what the unique dict is about? If so, could you add a comment here explaining why you are doing these operations so it's clearer?