A really great technique that you can use to formulate complex queries is to model the query using the mongo shell or use MongoDB Compass (covered in Chapter 9, Handling Complex Queries in MongoDB). That way, you are able to get an idea of what data is returned, which might lead to further refinements. You can then adapt the query to Python and the pymongo.collection.Collection.find() method.
In the mongo shell, we use the sweetscomplete database. After that, we can formulate our query document in the form of a JavaScript variable query. Next, we define the projection, which controls which fields appear in the output. We can then execute this query:
query = {"dateOfPurchase":{"$regex":/^2018/}};
projection = {"dateOfPurchase":1,"extendedPrice":1,"country":1,"_id":0};
db.purchases.find(query, projection). \
sort({"country":1,"dateOfPurchase":1});
We will achieve this...