Help me figure out what's wrong with mongodb challenge

when i run my test, it keeps saying “test timed out” like so

This is my code

const mongoose = require('mongoose')
const { Schema, model } = mongoose;

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true});
const personSchema = new Schema({
  name : {type: String, required: true},
  age :  Number,
  favoriteFoods : [String]
let Person = model('Person', personSchema);

const createAndSavePerson = (done) => {
  let doc = new Person({name: "pardon", age: 27, favoriteFoods: ['yam', "porriage"]});, data)=>{
    if (err) return console.error(err);
    done(null, data);

and for some reason i always get this error on the console

Your app is listening on port 3000
(node:3225) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘split’ of null
at parseSrvConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:40:23)
at parseConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:421:12)
at connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:188:3)
at connectOp (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:292:3)
at executeOperation (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
at MongoClient.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:168:10)
at /home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:527:12
at new Promise ()
at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:524:19)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/index.js:271:15)
at Object. (/home/runner/boilerplate-mongomongoose-1/myApp.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
(node:3225) 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 Command-line options | Node.js v17.4.0 Documentation). (rejection id: 3)
(node:3225) [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.

here is my project link


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.43

Challenge: Create and Save a Record of a Model

Link to the challenge:

Hello there,

Something to note:

  • Replit does not need the dotenv package to interact with environment variables
  • Within Replit, you should not have any .env files. Instead you should make use of the SECRETS tab located on the left task bar.
  • When you input your MONGO_URI in the SECRETS tab, try adding the value with and without quotation marks.

Hope this helps

1 Like

ok it worked after removing the quotation marks surrounding the secret key