MongoDB and Mongoose section

Hi folks, I’m facing hard time with database and MongoDB, Not because I don’t get the idea behind the task , no because whatever I do, my solutions did not pass the test !!!
In all tasks in this section none of my code work! when I go check the hint section and copy past (while my code is 99.99% identical) code, the test just pass ???

note: I’m working on this section on Replit website.

here is example =>

const  findPeopleByName = function(personName, done) {
  
  // CODE BELOW NOT PASSING THE TEST !!!
  
  // Person.find({ name: personName }, function(data, err) {
  //   if (err) return console.log(err);
  //   done(null, data);
  // });

  // CODE BELOW PASS THE TEST !!!
// ANY EXPLANATION WHY ? WHAT IS THE DIFFERENCE
  Person.find({ name: personName }, function(err, personFound) {
    if (err) return console.log(err);
    done(null, personFound);
  });
};

You have swapped the parameters.

The parameter order is not a user choice but a decision that was made for you when the API got created (in this case what is passed to the callback and in which order).

Model.find()

MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});

Just like with an array method, you can not swap the order.

[1, 2, 3].forEach((element, index, originalArray) => {
  console.log(element, index, originalArray)
})

The callback is passed the element, index, and the original array, in that order. If you swap the parameters.

[1, 2, 3].forEach((originalArray, index, element) => {
  console.log(element, index, originalArray)
})

Now originalArray is passed the element and vice versa.

1 Like

Thank you @lasjorg for clarifying the issue , obviously I was not paying enough attention to catch that!