You can’t use the localhost connection string. Use the connection string you get from MongoDB Atlas.
If you have it in the environment variable then remove the second mongoose.connect call.
mongoose.connect(process.env.MONGO_URI);
// remove this mongoose.connect and move the option object to the above mongoose.connect
mongoose.connect("mongodb://localhost:27017/monprojectWee", {
useNewUrlParser: "true",
useUnifiedTopology: "true"
})
After deleting this snippet of code I still get this error.
> node server.js
Your app is listening on port 3000
(node:310) UnhandledPromiseRejectionWarning: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/connection.js:686:11)
at /home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:330:10
at /home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:1151:10)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:329:20)
at Object.<anonymous> (/home/runner/boilerplate-mongomongoose-3/myApp.js:3:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
(node:310) 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:310) [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.
GET
MongooseError: Operation `people.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
GET
MongooseError: Operation `people.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
npm start
> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose-3
> node server.js
Your app is listening on port 3000
(node:19185) UnhandledPromiseRejectionWarning: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/connection.js:686:11)
at /home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:330:10
at /home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:1151:10)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose-3/node_modules/mongoose/lib/index.js:329:20)
at Object.<anonymous> (/home/runner/boilerplate-mongomongoose-3/myApp.js:3:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
(node:19185) 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:19185) [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.
type or paste code here
What did you call your cluster? my cluster is named cluster0
Also, never share your password online like you did there, even if you think little could be done with it, it could be used to trick you into getting more info from you
Thank you I managed to connect to the database and the information is displayed.
npm start
> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose-3
> node server.js
Your app is listening on port 3000
mongoose is connected
GET
{
name: 'xxx',
age: xx,
favoriteFoods: [ 'xx', 'xx', 'xx' ],
_id: new ObjectId("xxx"),
__v: xx
}