Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:41+00:00 2026-06-14T13:51:41+00:00

mturk_ops.block = function(callback){ mongodb.collection(collectionName, function(err, collection){ collection.distinct(‘workerId’,function(err,result){ var result1 = []; console.log(result.length); for(var i=0;

  • 0
mturk_ops.block = function(callback){


mongodb.collection(collectionName, function(err, collection){

    collection.distinct('workerId',function(err,result){
        var result1 = [];
        console.log(result.length);
        for(var i=0; i< result.length;i++){

            console.log(result[i]);

          result1[result[i]] =  collection.count({
                'workerId':result[i],
                "judgementStat" : "majority"
            },function(err, count){
                //  console.log(count);
              //  globals.push(count);
                return count ;
                // console.log( worker + ' majority : ' + count);

            });

        }

    console.log(result1);
    });


});

}

Here I am trying to print ‘result1’ but its always printing array with undefined value. ‘result1’ is an array which is assigned out of the scope of callback function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:51:42+00:00Added an answer on June 14, 2026 at 1:51 pm

    You can’t return a value from an asynchronous callback. The callback is usually executed some time after the function in which it was declared has returned (that function will continue execution after calling an asynchronous method). There is nowhere for a callback function to return to. Here’s a simple example:

    function doSomething() {
        var x = 10;
        doSomethingAsynchronous(function () {
            // This is a callback function
            return 30; // Where would I return to?
        });
        x += 10; // Execution continues here as soon as previous line has executed
        return x; // doSomething function returns, callback may not have run yet
    }
    

    If you need to rely on the result of an asynchronous method, you will need to move the code that requires it into the callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HIT on Mechanical Turk that requires a file upload of an
I'm trying to read a midi file in C++ and I'm stuck with an
I am creating hits at mTurk through Rspec test code but at the same
I've manually created a template and a task on Mechanical Turk. What's the easiest
How to convert this form PHP to AS3? $arr = explode( | , $str);
I know related questions are asked in other places but mine is different :)
I am facing this issue whenever i try to access a file which is
i want to disable phone browser and i want to use a webview .
Aloha - i would like to create an Amazon Turk task to collect information
Are there any APIs available which could help us do the following: Given a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.