简体   繁体   中英

Mongo Async Driver: How to invoke a method after completion for foreach method

I am writing a program for data migration. I want to invoke a method after complete execution of foreach method. In below code foreach(migrateJobsBlock, callback) callback method is invoked for every iteration. Is there any way I can invoke a method only after completion of foreach execution.

col1.find(filter).forEach(migrateBlock, callback).

Try something like:

var myCursor = db.doc.find( { filter } );

while (myCursor.hasNext()) {
   //do something
   var obj = myCursor.next()
}
// finished running! can run completion method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM