1.03K views
0 Comments

I tried to write the code by myself and clone if from your github , but it’s the same error everytime that i can’t get through.

Server Error
MongooseError: The `uri` parameter to `openUri()` must be a string, got “undefined”. Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

.next\server\pages\index.js (18:19) @ Object.connect
16 | await mongoose.disconnect();
17 | }
> 18 | const db = await mongoose.connect(process.env.MONGODB_URI, {});
| ^
19 | console.log(‘new connection’);
20 | connection.isConnected = db.connections[0].readyState;
21 | }

Call Stack
async getServerSideProps
.next\server\pages\index.js (62:2)

The problem seems to be at the mongodb
because the project works fine till the moment the mongoose comes in.

I can’t get the part to add a product to the cart.

Thanks for your time!
I love your videos 😀

Bassir Answered question October 11, 2022

do you have .env file in the root folder of the project and does it have this line:

MONGODB_URI=mongodb://localhost/amazona

follow this guide to set MongoDB connection:

https://github.com/basir/mern-amazona#run-locally

Bassir Answered question October 11, 2022