Rrunning the following snippet I would expect all of the finds to return the same result, however the middle on does not find any elements. Why doesn't the second case find anything and is there any way to use the nested element notation instead of dot notation with the mongodb operators?
from pymongo import MongoClient
client = MongoClient("mongodb://localhost:27017")
db = client['db']
collection = db["test_collection"]
collection.insert_one({"data": {"foo": "bar"}})
# {'_id': ObjectId('633aad8b587bc8057e240c96'), 'data': {'foo': 'bar'}}
print(collection.find_one({"data": {"foo": "bar"}}))
# None
print(collection.find_one({"data": {"foo": {"$in": ["bar"]}}}))
# {'_id': ObjectId('633aad8b587bc8057e240c96'), 'data': {'foo': 'bar'}}
print(collection.find_one({"data.foo": {"$in": ["bar"]}}))