title: how can i find distinct field in mongodb through node js
body: <p>look at the documents of my <strong>imageDetails</strong> collection:</p>
  
  <pre><code>&gt; db.imageDetails.find()
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e61"), "keyword" : "sachin", "name" : "sachin_1511554882309_1.jpg", "fullpath" : "Download/sachin_1511554882309_1.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e62"), "keyword" : "sachin", "name" : "sachin_1511554882317_2.jpg", "fullpath" : "Download/sachin_1511554882317_2.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e63"), "keyword" : "sachin", "name" : "sachin_1511554882319_3.jpg", "fullpath" : "Download/sachin_1511554882319_3.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e64"), "keyword" : "sachin", "name" : "sachin_1511554882319_4.jpg", "fullpath" : "Download/sachin_1511554882319_4.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e65"), "keyword" : "sachin", "name" : "sachin_1511554882320_5.jpg", "fullpath" : "Download/sachin_1511554882320_5.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e66"), "keyword" : "sachin", "name" : "sachin_1511554882320_6.jpg", "fullpath" : "Download/sachin_1511554882320_6.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e67"), "keyword" : "sachin", "name" : "sachin_1511554882320_7.jpg", "fullpath" : "Download/sachin_1511554882320_7.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e68"), "keyword" : "sachin", "name" : "sachin_1511554882320_8.jpg", "fullpath" : "Download/sachin_1511554882320_8.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e69"), "keyword" : "sachin", "name" : "sachin_1511554882320_9.jpg", "fullpath" : "Download/sachin_1511554882320_9.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6a"), "keyword" : "sachin", "name" : "sachin_1511554882320_10.jpg", "fullpath" : "Download/sachin_1511554882320_10.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6b"), "keyword" : "sachin", "name" : "sachin_1511554882321_11.jpg", "fullpath" : "Download/sachin_1511554882321_11.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6c"), "keyword" : "sachin", "name" : "sachin_1511554882321_12.jpg", "fullpath" : "Download/sachin_1511554882321_12.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6d"), "keyword" : "sachin", "name" : "sachin_1511554882321_13.jpg", "fullpath" : "Download/sachin_1511554882321_13.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6e"), "keyword" : "sachin", "name" : "sachin_1511554882321_14.jpg", "fullpath" : "Download/sachin_1511554882321_14.jpg" }
  { "_id" : ObjectId("5a187f4f2d4b2817b8448e6f"), "keyword" : "sachin", "name" : "sachin_1511554882322_15.jpg", "fullpath" : "Download/sachin_1511554882322_15.jpg" }
  &gt;
  </code></pre>
  
  <p>I want the distinct values of the field <strong>'keyword'</strong> in nodejs as replacement in mongodb like:</p>
  
  <pre><code>&gt; db.imageDetails.distinct('keyword');
  [ "sachin" ]
  </code></pre>
  
  <p>I tried but didn't find any efficient way in node js mongodb module, so please suggest any method to do so if there is option around aggregation or something more effecient. I am stuck:</p>
  
  <pre><code>MongoClient.connect(url, function(err, db) {
      if (err)
      throw err;
      var cursor = db.collection(collectionName).find(findQuery);
      cursor.each(function(err, doc)
  </code></pre>