PLEASE HELP Error on Create Many Records with model.create() Challenge

Tell us what’s happening:
Hello everyone,

I’ve spent the past few days stuck on the two challenges on MongoDB which has the error “Creating many db items at once should succeed (Test timed out)”. I’ve attempted the solutions in the hint and forum posts to no resolve. Thank you in advance,

--------------------.env file--------------------
MONGO_URI="mongodb+srv://adminUser:barracuda@fccmongouri.y97qq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"

--------------------myApp.js--------------------

require('dotenv').config();
/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

/** 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"]});

  janeFonda.save(function(err, data) {
    if (err) return console.error(err);
    done(null, data)
  });
};

/** 4) Create many People with `Model.create()` */
var arrayOfPeople = [
  {name: "Frankie", age: 74, favoriteFoods: ["Del Taco"]},
  {name: "Sol", age: 76, favoriteFoods: ["roast chicken"]},
  {name: "Robert", age: 78, favoriteFoods: ["wine"]}
];

var createManyPeople = function(arrayOfPeople, done) {
  Person.create(arrayOfPeople, function (err, people) {
    if (err) return console.log(err);
    done(null, people);
  });
};

--------------------package.json--------------------

{
    "name": "fcc-mongo-mongoose-challenges",
    "version": "0.0.1",
    "description": "A boilerplate project",
    "main": "server.js",
    "scripts": {
        "start": "node server.js"
    },
    "dependencies": {
        "body-parser": "^1.15.2",
        "dotenv": "^8.2.0",
        "express": "^4.12.4",
        "mongodb": "^3.6.4",
        "mongoose": "^5.12.0"
    },
    "repository": {
        "type": "git",
        "url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
    },
    "keywords": [
        "node",
        "mongoose",
        "express"
    ],
    "license": "MIT"
}

Your project link(s)

solution: boilerplate-mongomongoose.codingr0.repl.co

Your browser information:

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

Challenge: Create Many Records with model.create()

Hi,

I don’t immediately see a mistake in your function createManyPeople but I have noticed that the mongo_uri in your .env file is not yet correct. You should specifiy the name of your db, cluster0 or some other name you have chosen?

Could you check that .env file and see if that resolves the problem?

Greets,
Karin

1 Like

Hello Karin,

Thank you for the advice. Do you know how I can find the db name on the MongoDB Atlas interface?

Hi,

I think it’s FCCMongoURI . Replace ‘myFirstDatabase’ by that string inside your .env file

Greets,
Karin

1 Like

Hello Karin,

I replaced the database name in the .env file and the error message is “// running tests
Creating many db items at once should succeed (Test timed out)
// tests completed”.
.env file:

MONGO_URI="mongodb+srv://adminUser:barracuda@fccmongouri.y97qq.mongodb.net/FCCMongoURI?retryWrites=true&w=majority"

I can’t get a print screen so I’m copying the instructions:

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

Replace with the password for the KarinMeersman user. Replace myFirstDatabase with the name of the database that connections will use by default. Ensure any option params are URL encoded.

Where you write fccmongouri there’s cluster0. So, either this is cluster0 or FCCMongoURI instead of fccmongouri. I don’tknow my dbname stayed cluster0.
dLetulle may also be right about your username. Is adminUser what you chose?

Hope this makes sense,

Greets,
Karin

1 Like

Hello Karin,

Thank you for the suggestions. I renamed “cluster0” as FCCMongoURI when I first registered for MongoDB Atlas. The username is “adminUser” and the password is “barracuda” which I registered following the instructions on the challenge. Below is a screenshot of the database access page on Atlas.

Have you read my edit.
myFirstDatabase must be FCCMongoURI and cluster0 may be just that, or change it to FCCMongoURI and not fccmongouri like you wrote. These things are case sensitive. I suspect.

Greets,
Karin

1 Like

Thank you for the advice. I created a new cluster “cluster0” because the cluster name might be case-sensitive as you suggested and replaced the database name. I used the following combinations of keys, but none worked.

MONGO_URI="mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/cluster0?retryWrites=true&w=majority"
MONGO_URI="mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/Cluster0?retryWrites=true&w=majority"
MONGO_URI="mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"

What is the name now of your database? Is it still the same? If so, try:

MONGO_URI="mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/FCCMongoURI?retryWrites=true&w=majority"

or

MONGO_URI="mongodb+srv://adminUser:barracuda@FCCMongoURI.y97qq.mongodb.net/FCCMongoURI?retryWrites=true&w=majority"

If you’ve got a new DBname replace FCCMongoURI by that name

Don’t give up,

Karin

1 Like

The new cluster is “cluster0”. There may not be any database because when I click on the cluster, it says “Databases: 0 Collections: 0”.

I attempted the URIs you mentioned. I also used the following URI:

mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/cluster0?retryWrites=true&w=majority

Still the same EM or has anything changed?

1 Like

Could I ask what describes an EM?

error message. Like what you wrote earlier ‘test timed out’ . Still timing out?

1 Like

Yes, it states the same error.

I can’t see it.
I clicked on your link but I can’t see any code when I do, just the webpage, so I can’t look at the rest of your code. Can you either send a link that shows me all the code or can you paste it in another post?

1 Like

If you check the collection in your cluster, is it currently empty?

1 Like

Here is my code below. I don’t if the replit.com repo shares code. Thank you in advance.
----------.env file----------
MONGO_URI="mongodb+srv://adminUser:barracuda@cluster0.y97qq.mongodb.net/cluster0?retryWrites=true&w=majority"

----------myApp.js----------

require('dotenv').config();
/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

/** 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"]});

  janeFonda.save(function(err, data) {
    if (err) return console.error(err);
    done(null, data)
  });
};

/** 4) Create many People with `Model.create()` */
var arrayOfPeople = [
  {name: "Frankie", age: 74, favoriteFoods: ["Del Taco"]},
  {name: "Sol", age: 76, favoriteFoods: ["roast chicken"]},
  {name: "Robert", age: 78, favoriteFoods: ["wine"]}
];

var createManyPeople = function(arrayOfPeople, done) {
  Person.create(arrayOfPeople, function (err, people) {
    if (err) return console.log(err);
    done(null, people);
  });
};

----------package.json----------

{
    "name": "fcc-mongo-mongoose-challenges",
    "version": "0.0.1",
    "description": "A boilerplate project",
    "main": "server.js",
    "scripts": {
        "start": "node server.js"
    },
    "dependencies": {
        "body-parser": "^1.15.2",
        "dotenv": "^8.2.0",
        "express": "^4.12.4",
        "mongodb": "^3.6.4",
        "mongoose": "^5.12.0"
    },
    "repository": {
        "type": "git",
        "url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
    },
    "keywords": [
        "node",
        "mongoose",
        "express"
    ],
    "license": "MIT"
}

Hello JSDisco,

Thank you for the reply. Yes, the collection in the cluster states an entry. Could I ask how you could create an entry in the collection successfully using “adminUser” and the password “barracuda”?

Could you share your actual replit link? The page that you edit the code on, copy and paste that url.

1 Like