Home Mongoose cursor with async operations
Reply: 0

Mongoose cursor with async operations

user1153
1#
user1153 Published in April 19, 2018, 8:56 pm

I am new to mongo and now drowned in whole lot of documentation.All I want is to use mongoose cursor to work async with my data operation inside cursor.It should wait to play next iteration until operation is complete. I read in a that we can do so by

  • QueryCursor#eachAsync(fn, [options], [options.parallel], [callback])

  • If fn returns a promise, will wait for the promise to resolve

Since i am new to mongo I don't know how to create a promise and resolve it later.

var cursor = Users.find({ "is_verified" : false }).cursor();
cursor.eachAsync(function (doc) { 
    //create promise here
    async.series({
       one: function(callback){
          callback(null,1);
       },
       two: function(callback){
          callback(null,2);
       },
       three: function(callback){
          callback(null,3);
       },
       four: function(callback){
          //resolve promise here
          if() callback(null,4)
       },
   },function(err,result){})


}).then(()=>console.log('FINISHED'));
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296051 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO