title: Listing fields in a mongodb object
body: <p>I am developing a system where items can be shared with other users via an access key. I'm storing the access keys as fields within a <code>shareinfo</code> object (embedded within the item's document), as shown below:</p>
  
  <pre><code>shareinfo:{
      ........
      &lt;nth key&gt;: &lt;permissions object - may be complex and large&gt;
      ........
  }
  </code></pre>
  
  <p>When an item is accessed I check shareinfo.key and find if its valid or not.</p>
  
  <p>Currently, to list the keys I am loading (in Java) the entire shareinfo object in memory and running <a href="http://api.mongodb.org/java/current/org/bson/BSONObject.html#keySet%28%29" rel="nofollow">keySet()</a> on it to retrieve and return the keys <em>while the rest of the data is wasted</em>.</p>
  
  <p>Here's the problem: I want to get the list of keys (i.e. object field names) without the accompanying data (because in some cases the permissions object is noticeably large).</p>
  
  <p>I could not find any query in the mongodb docs for such a query. I want to know whether it's possible or not? Or is there an optimized way to load the list of field names into the application without the accompanying field values?</p>