'PyMongo: querying using json with a list

If I have some json like this:

query = {
   "canonical.operatingSystemFamily": "Linux",
   "canonical.region": "us-east-1"
}

I can pass that directly into find and it works:

self._db_conn[collection_name].find(query)

I want to do the same, but with lists, e.g.:

query = {
    "canonical.operatingSystemFamily": ["Linux","Windows"],
    "canonical.region": ["us-east-1", "us-east-2"]
}

Is there a way to do that? I know about "$in" but I do not want to have to parse my query data. This is a very simplified example, and there are a lot of fields that may or may not be there. Is there a way to use that json with lists directly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source