title: Query on MongoDB GridFS metadata (Java)
body: <p>What I'm trying to do is fetching a list of GridFS files by querying an field of the metadata. For example I got a GridFS file document looking like:</p>
  
  <pre><code>{ "_id" : { "$oid" : "4f95475f5ef4fb269dbac954"} , "chunkSize" : 262144 , "length" : 3077 , "md5" : "f24ea7ac05c5032f08808c6faabf413b" , "filename" : "file_xyz.txt" , "contentType" :  null  , "uploadDate" : { "$date" : "2012-04-23T12:13:19.606Z"} , "aliases" :  null  , "metadata" : { "target_field" : "abcdefg"}}
  </code></pre>
  
  <p>And I want to query all files containing "target_field" = "abcdefg". I created my query as follows:</p>
  
  <pre><code>BasicDBObject query = new BasicDBObject("metadata", new BasicDBObject("target_field", "abcdefg"));
  // gridFS Object Initialization skipped
  List&lt;GridFSDBFile&gt; files = gridFs.find(query);
  </code></pre>
  
  <p>The list is allways empty. Otherwise querying the filename or uploadDate works perfectly. Isn't it possible to get the GridFS files by nested attributes?</p>