0

I have this code :

  console.log("before querying");


  var x = collection.findOne(query)
    .then(function (retrievedData) {

     console.log("after querying");

     for (var i = 0; i < myArray.length || function() {

      console.log("looks like the loop is complete");
      return "";

      }(), false; i++)
        {
         console.log("entering loop...");
        }
    }

When I run this code, I see

before querying

Then the code crashes complaining that the function containing this code has not returned anything.

The actual error is this :

TypeError: Cannot read property 'then' of undefined

As you can see, I can't even see after querying. The code is running future steps before completing the .then part of findOne. I haven't posted all of the code since it's long and a bit complex. Could you tell me what I am doing wrong? Thank in advance.

jason
  • 6,962
  • 36
  • 117
  • 198

0 Answers0