Home Mongoose cursor with async operations
Reply: 0

Mongoose cursor with async operations

user1153 Published in July 16, 2018, 6:20 am

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
       one: function(callback){
       two: function(callback){
       three: function(callback){
       four: function(callback){
          //resolve promise here
          if() callback(null,4)

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO