2

Here's the error. It's blowing me up. Please help.

It's just getting mad at me for something that is not supported. And it's shouting at me not supported. I've never seen that many errors in the terminal. Can anyone tell me why I am getting this.

  DeprecationWarning: current Server Discovery and Monitoring engine is 

deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Server running on port 300
(node:6452) UnhandledPromiseRejectionWarning: MongooseError: Can't call `openUri()` on an active connection with different connection strings. Make sure you aren't calling `mongoose.connect()` multiple times. See: https://mongoosejs.com/docs/connections.html#multiple_connections    at NativeConnection.Connection.openUri (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\connection.js:682:13)
    at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:342:10
    at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
    at new Promise (<anonymous>)
    at promiseOrCallback (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
    at Mongoose.connect (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:341:10)
    at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\models\Url.js:10:27)    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\routes\url.js:7:13) 
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
(node:6452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Server running on port 300
(node:6452) UnhandledPromiseRejectionWarning: MongooseError: Can't call `openUri()` on an active connection with different connection strings. Make sure you aren't calling `mongoose.connect()` multiple times. See: https://mongoosejs.com/docs/connections.html#multiple_connections    at NativeConnection.Connection.openUri (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\connection.js:682:13)
    at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:342:10
    at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
    at new Promise (<anonymous>)
    at promiseOrCallback (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
    at Mongoose.connect (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:341:10)
    at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\models\Url.js:10:27)    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\routes\url.js:7:13) 
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
(node:6452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 MongoDB Connected...

Here's the link to my code

Dingus45191
  • 532
  • 1
  • 7
  • 19

1 Answers1

2

It's all about mongo connection:

  1. Your params passed to mongoose.connect in ./models/url.js are incorrect:

The first param of mongoose.connect is a mongo connection string and the second is an options (passed down to mongo.connect) or a callback, which should be something like

module.exports = mongoose.connect('mongodb://user:pass@localhost:port/database', { useNewUrlParser: true });

You can find its offcial docs here: https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-connect

  1. Remember that mongoose.connect is an async function, using require("../models/Url") in ./routes/url.js will lead to unexpected result.
Hoang Dao
  • 775
  • 5
  • 16
  • I did as you said and I updated my question with new errors which I got – Dingus45191 Nov 10 '20 at 05:45
  • 1
    @Dingus45191 the warning is so clear, just pass another option `useUnifiedTopology: true` to `mongoose.connect`, the error is because of your `./routes/url.js` which use the old `./models/url.js` file, please read my answer carefully – Hoang Dao Nov 10 '20 at 05:54