title: Nodejs and MongoDB : Unable to return value from a function
body: <pre><code>var config = require('config.json');
  var mongo = require('mongoskin');
  var db = mongo.db(config.connectionString, { native_parser: true });
  
  module.exports.getNextSequence =  function (name) {
      var temp;
      db.collection("counters").findAndModify(
          { _id: name },           // query
          [],                      // represents a sort order if multiple matches
          { $inc: { seq: 1 } },    // update statement
          { new: true },           // options - new to return the modified document
          function (err, doc) {
              temp = doc.value.seq;
              console.log(temp);   // &lt;-- here the temp is getting printed correctly
          }
      );
      return temp; 
  }
  </code></pre>
  
  <p>Using the above code, I am not able to return the value of <code>doc.value.seq</code>. When doing <code>console.log(obj.getNextSequence)</code> it prints <code>undefined</code>.</p>
  
  <p>I want the function to return the value of <code>doc.value.seq</code>.</p>