Hi,
i’m stuck on this challenge: Use model.findById() to Search Your Database By _id.
Both my code and the solution code of freecodecamp give out an [object Object], failing the test. I have no idea where it goes wrong.
app.js code (commented out code is my own, the not-commented out code is the freecodecamp solution):
/*
const findPersonById = (personId, done) => {
Person.findById({_id:personId},function(err,data){
if(err) return console.error(err);
done(null, data);
})
};
*/
var findPersonById = function(personId, done) {
Person.findById(personId, function (err, data) {
if (err) return console.log(err);
done(null, data);
});
};
Console output:
node v12.16.1
GET
[object Object]
[object Object]
I forked your project and added my own MONGO_URI and it passes the challenge with no strange output. Are you seeing any errors in the Node console when npm start runs?
npm start
fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
node server.js
the options [useUnifiedTopology] is not supported
Your app is listening on port 3000
(node:995) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
GET
[object Object]
GET
[object Object]
GET
[object Object]
GET
It’s weird, but to pass test findPersonById and all the following ones except the last, I had to put in the solution links one for one again in the fCC “Back End Development and APIs”(https://www.freecodecamp.org/learn/back-end-development-and-apis), then it passed…
However the last challenge Nr 12, it doesn’t work with this helparound.
Now Im stuck again, even though the solution should be fine (checked it with hints and a YouTuber who went through the challenges.)