MongoDB and Mongoose - Use model.findOne() to Return a Single Matching Document from Your Database

I’ve tried entering my program to findOneByFood function but, it seems to not work as it says there is an error. I have run the program package several times to see if maybe that might be causing the error but, that seems to not work.

Your project link(s)

solution: boilerplate-mongomongoose-3 - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.124 Safari/537.36 Edg/102.0.1245.41

Challenge: MongoDB and Mongoose - Use model.findOne() to Return a Single Matching Document from Your Database

Link to the challenge:

Use correct user password from your database. Not password of your Mongo account. Avoid angle brackets.
let uri = must use the same sample.env content and ends with semicolons.

it still seems to give an error. It says an unexpected end on the input but, there isn’t any unexpected end on the input that I can change.

Show your project link.

myApp.js - boilerplate-mongomongoose-3 - Replit

What is being said in the error?

unexpected end input

First of all, in the sample.env file, add it correctly a MONGO_URI variable: MONGO_URI=‘VALUE’.
MONGO_URI=‘mongodb+srv://:@-vlas9.mongodb.net/test?retryWrites=true’
Replace with the password for the user.
Avoid all angle brackets.
Instead of test? put your database name followed by?

I think I’ve got him: first argument should be data and not error, am I right icxc?

I’m wrong, sorry about that

well done I think😆
you copied the code to your own replit so ou could run it?

I’ve done that as well but still seem to get the same error of unexpected end input

I’ve added the missing closing and opening {}, but still seems to be the same unexpected end input

There were 3 missing } and 1 missing {. You still have issues with your code after fixing these, but the error message that shows indicates your Mongo connection string is missing a database name. Also, I notice you are not use the specified version of mongoose (^5.4.0). The version may or may not cause you problems working through this sections challenges.

NOTE: I still see at least one missing }. If you indent your code properly, it is much easier to see when you are missing { or }. You can optionally use a JS Beautifier that will indent the code for you. You would copy/paste into it and then get the results to paste back into your replit.

I’ve updated the version and added the last } and it works now!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.