Creating and saving a db item should succeed (Test timed out)

Tell us what’s happening:
When I run the test for my project the console logs MongooseError: Operation people.insertOne() buffering timed out after 10000ms. What could be the problem?
Your project link(s)

solution: https://boilerplate-mongomongoose.nicholasmukuha.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: Create and Save a Record of a Model

Link to the challenge:

Hello!

It may be because there’s an error and you’re not calling done in that case:

  student.save(function(err, data){
    if(err){
      // Here, what happens if the err variable is not empty?
      // The done function is never called here, hence it may never finish (timeout)
      console.log(err);
    } else{
      done(null, data);
    }
  });

If that doesn’t solve the problem, could you post the error message you see on the logs?

Hello. Thank you for your response. I wrote the code, exactly as you’ve written above, but when I submit the challenge, it responds with “MongooseError: Operation people.insertOne() buffering timed out after 10000ms
at Timeout. (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)”

1 Like

It seems I didn’t explain it well :stuck_out_tongue:.

I saw the code, of course, but there may be an error when you save the person (student), in which case the function never ends.

You should write this:

    if(err){
      // Here, what happens if the err variable is not empty?
      // The done function is never called here, hence it may never finish (timeout)
      console.log(err);
      done(err);
      // Or simply pass the done function to the .save instead
    } else{
      done(null, data);
    }

Try that and let us know :slight_smile:.

I think the problem is that your database is not accessible.

Can you check that your mongodb atlas database is accessible publicly? You will need to modify the firewall rules. In your account (on https://cloud.mongodb.com), you have to click on Security → Network Access and create a rule with 0.0.0.0/0 for the database myFirstDatabase.

Hello.

I have done that,but it still gives me the same error message. I’m stuck😭

I tested the project with my own mongodb account and it works, so the problem is with your configuration.

Please, make sure the user and password matches the one allowed to access the database/collection (on your atlas account → SecurityDatabase Access).

Also, you must copy use the same string shown when you click on Connect, as shown in the following image (bottom right):

This is my URL (it may differ):

mongodb+srv://<username>:<password>@cluster0.9m0ms.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

Where I need to replace <username> and <password> with the ones shown in my atlas account under SecurityDatabase Access (it’s not the same as your atlas account). myFirstDatabase must be replaced with one of the Collections on your atlas account.

I hope it helps :slight_smile:

On more thing.

I edited your project to let you know if the connection was successful:

image

If the message Connection stablished is not shown, then there’s still a problem with the configuration on your database.