Where is my data in MongoDB?

Hi All,

I’ve passed the challenge on Create Many Records with model.create() for the APIs and Microservices curriculum.

My code under replit is as follow:

 const arrayOfPeople = [
 {
     name: "John Doe",
     age: 29,
     favoriteFoods:["Fried Chicken", "Bread", "Eggs"]
 },
 {
     name: "Marry Jane",
     age: 33,
     favoriteFoods:["Fruits", "Nuts", "Toast"]
 },
 {
     name: "Caithlin Holmes",
     age: 25,
     favoriteFoods: ["Tomatoes", "Potatoes", "Olives"]
 },
 {
     name: "Anne Johnson",
     age: 38,
     favoriteFoods: ["Pizza", "Spaghetti", "Soup"]
 },
 ]
 const createManyPeople = (arrayOfPeople, done) => {
     Person.create(arrayOfPeople, function(err,people){
         if (err) return console.log(err);
         done (null, people);
     });
 };

My question is I can’t find these “people” in my mongoDB i’ve linked for the challenge. The screen shot of the data in mongoDB is as follow:

The entries in the database is not what I have created. So I’m kinda lost as to what happen to the data that I have created and how did I pass the challenge?

Appreciate if anyone could clear up my understanding.

Thanks in advanced.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Create Many Records with model.create()

Link to the challenge:

When you run the test FreeCodeCamp runs your code with a bunch of test cases populating your database

Hi caryaharper,

Thanks for your reply but would not my arrayOfPeople be created together with the test cases of FreeCodeCamp?

Because it seems like none of my entries were created.

If my code did not populate the database then I’m curious what my code did instead?

Thank you!

If you ran that exact file, and everything was set up properly then from my knowledge that data should be in your data base.

Hi caryaharper,

I think I understand where you are coming from. Could you direct me to a tutorial or article that could teach me how to do the proper set up?

Thank you =)

I hope this helps:

Hi,

Atlas free db has it’s limitations, you can run tests multiple times which may lead to exceeding them quickly, the service is good for testing/learning purposes though. To my knowledge, when you run FCC tests they add their records and then drop db (==delete all records) at some point ), not sure at which challenges, maybe all of them (upd: source of truth) . You can check testing part and find out

Hello there,

Just to mention it for reduced confusion: The freeCodeCamp tests delete the records in your database after adding them. From what I can see, there should be no documents left in your database, unless you manually added them:

const createPeople = require("./myApp.js").createManyPeople;
router.post("/create-many-people", function (req, res, next) {
  Person.remove({}, function (err) {
    if (err) {
      return next(err);
    }
    // in case of incorrect function use wait timeout then respond
    let t = setTimeout(() => {
      next({ message: "timeout" });
    }, TIMEOUT);
    createPeople(req.body, function (err, data) {
      clearTimeout(t);
      if (err) {
        return next(err);
      }
      if (!data) {
        console.log("Missing `done()` argument");
        return next({ message: "Missing callback argument" });
      }
      Person.find({}, function (err, pers) {
        if (err) {
          return next(err);
        }
        res.json(pers);
        Person.remove().exec();
      });
    });
  });
});

Hope this helps

1 Like

Hi Sky020,

Thanks for pointing it out. However I didn’t add anything into the database manually…I’m still wondering where those entries come from though at least now I’m clear why the entries I coded were not in the database.

Cheers!

Hi Annestezia,

Thanks for sharing!

1 Like

iirc, when you write the create function, the delete one isnt available yet, so whatever entries you tested(and added to the DB) would stay there. Once you write the delete function and FCC test it, it would delete only the specific entries queued by the delete command.

Hi Sylvant,

I think you are referring to the exercises in creating and deleting documents.

However I think the issue here is that the test script used to test our completed exercises is deleting our entries after the test.

Thanks for your response.