Help with Model create

Help with Model create
0

#1

Hello Dev’s
I’m try to solve the “MongoDB and Mongoose - Create a Model” exercise and don’t have success.

I read the questions about this exercise, but the message that i receive is: “not found”
Anybody can help me, to identify what is wrong with the code above?

Thanks in advance.

My Code:


var express = require('express');
var app = express();
var mongoose = require('mongoose');

app.get("/", function(req, res, next) 
{ 
  if(process.env.MONGODB_URI)
  {     
    mongoose.connect(process.env.MONGODB_URI);
    // connect to the server
    var db = mongoose.connection; 
    // check connection errors
    db.on('error', console.error.bind(console, 'connection error:'));
    // Once established connection
    db.once('open', function(done)
    {
         var Schema = mongoose.Schema;
         var PersonSchema = new Schema(
         {
           name: 
           {
            type: String,
            required: true
           },             
           age:   Number,
           favoriteFoods :[ String]     
         });
         var PersonModel = mongoose.model('Person', PersonSchema);
         PersonModel.create({ name: 'Teste', age: 18, favoriteFoods: ['Pao','Hamburger'] }, function (err, small) 
         {
            if (err) return res.end(err);  

            done();
         });
    });
  }  
});

#2

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 easier to read.

Note: Backticks are not single quotes.

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


#3

Thank’s ArielLeslie.
In future, will write in a better form.