Start a new topic

fineOne doesn't called


here is a part of endpoint script

Assuming that

- requestedIds is a collection of object ids that should be fetched. Let's assume it was initialized with ["SNWHotspot1", "SNWHotspot2"]

- UpdateResponse is a function that updates responseInt string array that whould be printed to response at the end of the process.

- reqBody is a request body object

    var calls = [];     


      UpdateResponse(EnumStatus.SUCCESS, "Within forEach");

      calls.push(function(callback) {

        UpdateResponse(EnumStatus.SUCCESS, "Within push");

        var collectionName = <some existing or non-existing collection name>;

        UpdateResponse(EnumStatus.SUCCESS, " " + reqBody[name]._id);

        db.collection(collectionName).findOne({_id:reqBody[name]._id}, null, function(error, doc) {

          UpdateResponse(EnumStatus.SUCCESS, "Within findOne");

            if (err)


              UpdateResponse(EnumStatus.ERROR, "push with error: " + err.message);

              return callback(err);


            UpdateResponse(EnumStatus.SUCCESS, name + "checked");

            callback(null, name);




    UpdateResponse(EnumStatus.SUCCESS, "Calls count: " + calls.length);

    modules.async.parallel(calls, function(err, result) {

      UpdateResponse(EnumStatus.SUCCESS, "Within parallel");

       if (err) 

        return UpdateResponse(EnumStatus.ERROR, "Result with error: " + err.message);

      UpdateResponse(EnumStatus.SUCCESS, result);



    response.body = JSON.stringify(responseInt);


Fot the following input:


  "SNWHotspot1" :


    "_id" : "SNWHotspot1",

    "somefield1" : 1,

    "someOtherField1" : 2


  "SNWHotspot2" :


    "_id" : "SNWHotspot2",

    "somefield1" : 3,

    "someOtherField1" : 4



this code with responses with:

200 SUCCESS -- "{\"status\":true,\"message\":[\"requestKey: SNWHotspot1\",\"requestKey: SNWHotspot2\",\"Within forEach\",\"Within forEach\",\"Calls count: 2\",\"Within push\",\" SNWHotspot1\",\"Within push\",\" SNWHotspot2\"],\"error\":[]}"

As you can see there is no call or no callback to/from findOne function.

Any idea why?

1 Comment

Good morning Art,

The findOne function is a part of the collectionaccess module.   

An example of a call using it may look like this:

modules.collectionAccess.collection(collectionName).findOne({_id: reqBody[item]._id}, function(error, doc)


Login or Signup to post a comment