title: List all values of a certain field in mongodb
body: <p>How would I get an array containing all values of a certain field for all of my documents in a collection?</p>
  
  <p>db.collection:</p>
  
  <pre><code>{ "_id" : ObjectId("51a7dc7b2cacf40b79990be6"), "x" : 1 }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be7"), "x" : 2 }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be8"), "x" : 3 }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be9"), "x" : 4 }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990bea"), "x" : 5 }
  </code></pre>
  
  <p>"db.collection.ListAllValuesForfield(x)"
  Result: [1,2,3,4,5]</p>
  
  <p>Also, what if this field was an array?</p>
  
  <pre><code>{ "_id" : ObjectId("51a7dc7b2cacf40b79990be6"), "y" : [1,2] }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be7"), "y" : [3,4] }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be8"), "y" : [5,6] }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990be9"), "y" : [1,2] }
  { "_id" : ObjectId("51a7dc7b2cacf40b79990bea"), "y" : [3,4] }
  </code></pre>
  
  <p>"db.collection.ListAllValuesInArrayField(y)"
  Result: [1,2,3,4,5,6,1,2,3,4]</p>
  
  <p>Additionally, can I make this array unique? [1,2,3,4,5,6]</p>