MongoDB and Mongoose - Create and Save a Record of a Model, Creating and saving a db item should succeed

Please help I can’t find the solution how to pass this challenge
here’s my code

var mongoose = require('mongoose');
 var Schema = mongoose.Schema;

var personSchema = new Schema({
  name: {
    type: String,
    required: true
  age: Number,
  favoriteFoods: [String]

var Person = mongoose.model('Person', personSchema);

var createAndSavePerson = function(done) {
  var dingusMan = new Person({name: "Dingus", age: 8, favoriteFoods: ["beef", "cheetos"]});, data) {
    if (err) return console.error(err);
    done(null, data)


I have this error
Creating and saving a db item should succeed

Thanks in advance

Welcome, jhaycawasa.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


To help your question: If you have run the script to create a model, and it was not 100% correct to begin with, then your database has an incorrect collection, and you could try:

  1. Going into your Mongo account, and clearing all records.
  2. Re-running the tests/script.


  1. Go back to the first challenge, and concurrently complete all of them again.

Hope this helps

Just wanted to update this, I was struggling with this and this was good advice! But it took me a bit of research to clear all records.

When you start with Mongo, as is not specified in the challenges, you have to create a collection. I created one (database name “dbtest” and collection name also “dbtest”) and then you have to change the bit in your URI to whatever you set it to. Was having trouble just because there was no collection for Mongo to access. Hope this helps, this challenge took me forever to pass

Hey there,

Good point. This could do with mentioning during the first lesson, in case Campers get stuck.

This is not quite true, because the default URI contains 'test' (mentioned here). Also, using Mongoose (as this challenge does) automatically creates a database (typically with the same name as the collection).

Ah! Also, I didn’t end up fixing it lol, about to post again.

but yes, thank you for responding! On me for not seeing the default URL bit.

Also, seems like fCC has migrated to Glitch? All of the challenges in this section cite but all of the responses on the forum suggest using Glitch. Might be useful to change some of those (I was thinking of sending in PRs over the next few days for what it’s worth, just have been busy!)

The opposite, actually. Around August, 2020, we migrated from Glitch to

If you can think of a decent way to make Campers aware of the possible need to delete documents in the database, then a PR would be welcome.

If you have not recently, remember to read the Contributors Docs.

Will read the contributor docs! Have seen a few things I wanted to tweak but have not gotten around to setting up an environment/actually tweaking things.

Was mainly thinking something like “NOTE: We were previously encouraging campers to use Glitch instead of, so posts on the freeCodeCamp forum may refer to Glitch. Most of this advice is applicable to projects on as well.” or something like that but perhaps more eloquent.