1

When I run my node.js code I get the error:

d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\core\uri_parser.js:585
    return callback(new MongoParseError('Invalid connection string'));
                    ^

MongoParseError: Invalid connection string
    at parseConnectionString (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\core\uri_parser.js:585:21)
    at connect (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\operations\connect.js:283:3)
    at d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\mongo_client.js:284:5
    at maybePromise (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\utils.js:692:3)
    at MongoClient.connect (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongodb\lib\mongo_client.js:280:10)
    at d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\connection.js:836:12
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\connection.js:832:19)
    at d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\index.js:351:10
    at d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\index.js:1149:10)
    at Mongoose.connect (d:\Default Download\Ace Bot\Ace Bot\node_modules\mongoose\lib\index.js:350:20)
    at Object.<anonymous> (d:\Default Download\Ace Bot\Ace Bot\index.js:24:4)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)

I am new to mongoose and have no idea if this is a simple error, sorry if it is. Here is my code:

const mongoose = require("mongoose");
mongoose
  .connect(config.mongoose, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: false,
    useCreateIndex: true,
  })
  .then(console.log("MongoDB Conneted.."));

1 Answers1

1

Instead of config.mongoose you will need to insert a URI here so that Mongoose can connect to MongoDB mongodb://localhost/[yourDbName].See more on this post

Staxlinou
  • 1,351
  • 1
  • 5
  • 20
Djre
  • 61
  • 9
  • Dumb question but...how would I know my database name? (Not my code) – AceKiller250 Oct 16 '21 at 03:35
  • There is a lot of useful information here in the documentation: https://mongoosejs.com/docs/connections.html – Djre Oct 16 '21 at 03:37
  • If you're following a tutorial and using a website like MLab you could check the DB name that you set up there on the website or in a config folder that you set up for the Mongo URI like keys.js – Djre Oct 16 '21 at 03:43
  • @AceKiller250 did the 'MongoParseError: Invalid connection string' link & explanation I provided help you? If so, could you please accept my answer? – Djre Oct 18 '21 at 09:48