View previous topic :: View next topic |
Author |
Message |
Beatrixxx n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 31 Jul 2019 Posts: 1 Location: Brussels
|
Posted: Wed Jul 31, 2019 3:09 pm Post subject: Help needed with Mongodb error |
|
|
Hello everyone,
Help needed ! Trying to connect to the database in the Mongodb Atlass cloud :
Code: | const express = require ('express')
const mongoose = require ('mongoose')
const path = require ('path')
const keys = require ('./ keys')
const port = process.env.PORT || 5000
const clientPath = path.join (__ dirname, 'client')
mongoose.connect (keys.mongoURI)
.then (() => console.log ('MongoDB connected.'))
.catch (err => console.error (err))
const app = express ()
app.use (express.static (clientPath))
app.listen (port, () => { console.log (`The server started on the port $ {port}`) })
**File:keys.js**
module.export = {
mongoURI:'mongodb+srv://xxxusername:xxxpassword@cluster0-m3jmz.mongodb.net/mdbtest?retryWrites=true'
}
**An error is displayed in the terminal:**
C:\Users\user\Desktop\fullstack-blog\node_modules\mongoose\lib\connection.js:459
throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
^
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.co
nnect()` or `mongoose.createConnection()` is a string.
at new MongooseError (C:\Users\user\Desktop\fullstack-blog\node_modules\mongoose\lib\error\mongooseError.js:14:11)
at NativeConnection.Connection.openUri (C:\Users\user\Desktop\fullstack-blog\node_modules\mongoose\lib\connection.js:459:11)
at Mongoose.connect (C:\Users\user\Desktop\fullstack-blog\node_modules\mongoose\lib\index.js:289:15)
at Object.<anonymous> (C:\Users\user\Desktop\fullstack-blog\app.js:9:10)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
[nodemon] app crashed - waiting for file changes before starting... |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
e3k Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
![](images/avatars/1575931814664a37f3cd44d.gif)
Joined: 01 Oct 2007 Posts: 515 Location: Quantum Flux
|
Posted: Mon Aug 12, 2019 4:50 pm Post subject: Re: Help needed with Mongodb error |
|
|
maybe you want to remove the space here before keys?
Code: | const keys = require ('./ keys') |
->
Code: | const keys = require ('./keys') |
_________________
Flux & Contemplation - Portrait of an Artist in Isolation
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|