Model.find() - MongoDB and Mongoose

Model.find() - MongoDB and Mongoose
0

#1
var findPeopleByName = function(personName, done) {
    Person.find(personName, function (err, data) {
    if(err){
      return done(err);
    }
    return done(null, data);
    })
};

Why does this not work? The test console returns that “Parameter “filter” to find() must be an object, got [email protected]


#2

Have you figured it out? If not, I can help. I ran into the same problem, but then realized that personName isn’t an object, so I turned it into an object and it worked.


#3

No. I have not figured it out. How do I convert the parameter to an object? I tried using JSON.parse(personName) but it does not pass the test.


#4

I found the answer. {name: personName} worked


#5

Thank you very much for your help.


#6

Could you paste your working code? I’m having trouble understanding where to put {name: personName}.
Thanks :slight_smile:


#7

You gotta replace personName parameter into an actual JSON with key : value pair like the author did.


#8

I’m still confused on what to do with the {name: personName}. I tried putting it in my package.json file with no luck. Can someone please send their code and how they got the answer. Thank you!


#9

Never mind, I figured it out.


#10

The doc for find query