title: How to get mongoDB collection size in node js?
body: <p>I'm trying to connect to a mongoDB DB, and make some processes on a collection, and close the collection when all the collection items were processed. when I'm trying to receive array.length, I get undefined. </p>
  
  <pre><code>Db = require('mongodb').Db;
  Server = require('mongodb').Server;
  const db = new Db(DB_NAME, new Server(HOST, PORT));
  // connect to mongoDB
  db.open(function (err, db) {
    const Collection = db.collection(COLLECTION_NAME);
    var items = Collection.find({});
    var itemsLength = items.lebgth;
    var itemsProcessed = 0;
    items.forEach((item, index, array) =&gt; {
      // some process like:
      Collection.update({query}, {set}, callback)
      itemsProcessed++;
      if(itemsProcessed == array.length){
        db.close();
        // close connection if all items were processed
      }
    });
  });
  </code></pre>
  
  <p>Is there any other way to do it?</p>