Create & Save record of a model - time out issues

Tell us what’s happening:
I am trying to complete the challenge “Create and Save a Record of a Model” but always get the same error…

I tried with the code provided in the hint:

/** 1) Install & Set up mongoose */

const mongoose = require('mongoose');

/** 2) Create a 'Person' Model */
var personSchema = new mongoose.Schema({
  name: String,
  age: Number,
  favoriteFoods: [String]

/** 3) Create and Save a Person */
var Person = mongoose.model('Person', personSchema);

var createAndSavePerson = function(done) {
  var janeFonda = new Person({name: "Jane Fonda", age: 84, favoriteFoods: ["eggs", "fish", "fresh fruit"]});, data) {
    if (err) return console.error(err);
    done(null, data)

In the console, I have some deprecation warnings when I run my code:

(node:1159) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. Your app is listening on port 3000 (node:1159) [MONGODB DRIVER] Warning: 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.

When I run the tests to complete the challenge it displays “GET” but then nothing, and I get the message “Creating and saving a db item should succeed” in the exercise.

I don’t think that the deprecation warnings are important, but still I don’t manage to pass the challenge even though the code is correct, and I have created a secret environment variable MONGO_URI mongodb+srv://

Your project link(s)

solution: boilerplate-mongomongoose - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15

Challenge: Create and Save a Record of a Model

Link to the challenge:

Not sure if it is causing your timeouts, but the two deprecation warnings do coincide with the notes I took from class in how to connect:

mongoose.connect(URI, {useNewUrlParser: true, useUnifiedTopology: true})

During the class that’s how connecting was presented… might see if that fixes your timeout issues.

Hi @kinome79 !
Indeed this removed completely the deprecation warnings - thanks a lot!

It didn’t solve the issue I had though but I managed to pass the challenge by creating a new repl and copy pasting my code in it. Maybe I broke something in the code for the testing in my previous repl.

Thanks for the help !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.