'Whenever i am trying to connect my server with mongodb it is showing this error. Whats the problem?
This is my code. I think everything is good but showing this error [nodemon] app crashed - waiting for file changes before starting..
async function run() {
try {
await client.connect();
const collection = client.db("motorcycle").collection("items");
app.get('/items', async(req, res) =>{
const query = {};
const cursor = collection.find(query);
const items = await cursor.toArray();
res.send(items);
})
} finally {
await client.close();
}
}
run().catch(console.dir);
app.listen(port, ()=>{
console.log('Listening', port)
}
Solution 1:[1]
- Your MongoDB Connection URI is invalid
- On line
3, where you runawait client.connect(), you aren't specifying the MongoDB Connection URI. Change your code to beawait client.connect(URI), whereURIis your connection string.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Exortions |
