Question: I persist my Python classes to JSON and write them to MongoDB. I'm using a JSON Encoder which has been presented [here](http://pymotw.com/2/json/). This results in a slight complex JSON structure which does not follow the simple "string" key/values in all the MongoDB tutorials. Here is an excerpt of a class written to JSON:

```
{
    "_id" : ObjectId("51f2397c86a49a5e6dec4633"),
    "__module__" : "experiment.experimentmanager",
    "experiments" : {
        "FOO" : [
            {
                "__module__" : "experiment.experiment",
                "enable_routing_table_trace" : false,
                "__class__" : "Experiment",
                "scenario_name" : "foobar",
                "enable_network_visualize" : false
            },    
}

```

I'm wondering how I could check for example if there is a key "FOO" in experiments using MongoDBs find? Thanks in advance!

Answer: 
To check if field exists [use`$exists` operator](http://docs.mongodb.org/manual/reference/operator/exists/).

To access complex structures use dot notation. For example:

```
db.inventory.find( { "experiments.FOO": { $exists: true} } )

```
This query should work:

```
db.collection.find({
    "experiments.FOO": {
        $exists:true
    }
});

```