Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Help needed with Mongodb error
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Beatrixxx
n00b
n00b


Joined: 31 Jul 2019
Posts: 1
Location: Brussels

PostPosted: Wed Jul 31, 2019 3:09 pm    Post subject: Help needed with Mongodb error Reply with quote

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
View user's profile Send private message
e3k
Guru
Guru


Joined: 01 Oct 2007
Posts: 515
Location: Quantum Flux

PostPosted: Mon Aug 12, 2019 4:50 pm    Post subject: Re: Help needed with Mongodb error Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum