title: mongodb - project element in array
body: <p>a doc <code>{"m":[1,2,3], "others":xxx}</code>, get the first element in array 'm' by:</p>
  
  <pre><code>db.find({query},{"m":{$slice:1}, "m":1})
  </code></pre>
  
  <p>the return is <code>{"m":[1]}</code>, the element in doc is an array. But in this query, only one element in array will be get, so I don't need the return doc contain array which has only one element.  This is like SQL local variable in sub-query. The element I want has no name in original doc, if I want get it then I need to make a name for it, the doc returned I wanted is like:  {"localVariable":1} rather than {"m":[1]}</p>
  
  <p>I try to project out the first element by:</p>
  
  <pre><code>db.find({query},{"m":{$slice:1}, "m.1":1})
  </code></pre>
  
  <p>but this don't work.</p>