MongoDB and Mongoose - Create and Save a Record of a Model - Help!

Hi friends, I am having trouble with this lesson, even after viewing the relevant forum posts. Here is a link to my glitch file: Click me.

Essentially when I submit my glitch link to the lesson page, the resulting comment is only “28” and an “X” below indicating that I am failing the test.

const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

var Schema = mongoose.Schema;

var personSchema = new Schema({
    name: String,
    age: String,
    favoriteFoods: [String]
  });
var Person = mongoose.model('Person', personSchema)

var createAndSavePerson = function(done) {
 var person = new Person({name: 'Patrick', age: 47, favouriteFoods: ['hotdogs', 'beers', 'pasta']})
 person.save((err, data) => (err ? done(err) : done(null, data)))};

Help?

favoriteFoods instead of favouriteFoods

@six03 he spelled that correctly,
@Curtis
change your type of age from string to Number,
let me know if that doesnt work and ill give you the next step.

1 Like
var createAndSavePerson = function(done) {
var person = new Person({
    name: 'Patrick', 
    age: 47, 
    favouriteFoods: ['hotdogs', 'beers', 'pasta']})
person.save((err, data) => (err ? done(err) : done(null, data)))};

Not on that 5th line. It’s the Americanized spelling, not the proper English spelling.

2 Likes

@six03 is right, the spelling is not consistent throughout the code.
@kravmaguy is also right regarding the type of age should be Number.

2 Likes

This is what I have, which passed.

var createAndSavePerson = function(done) {
var person = new Person({
  name: 'Todd', 
  age: 48, 
  favoriteFoods: ['sushi', 'lobster', 'pasta']})
person.save((err, data) => (err ? done(err) : done(null, data)))};

Thanks all! Those two fixes passed.

this is supposed to be in app.js. right?

i tried many solutions but i just get “time out has occurred” error.

Yes, for Step 3.


/** 3) Create and Save a Person */

thank you but i found out that maybe API and micro-services part is broken. thank you anyways.
still this is correct right?

var createAndSavePerson = function(done) {
var person = new Person({
name: ‘Sven’,
age: 13,
favouriteFoods: [‘bones’, ‘meat’]})
person.save((err, data) => (err ? done(err) : done(null, data)))};

@krutarth there is no way to know if your code is right without seeing more code. You may have the same spelling problem as the OP, so review the prior responses.