MongoDB and Mongoose challenges

Hi there,

I am conducting the MongoDB and Mongoose challenges, and I cannot get them to pass for the life of me, the crazy thing is, they actually deliver the desired result, and my mlab database has the documents uploaded to it.

Is anybody else having this issue? As it stands I am skipping the passing part and continuing at my own pace, as it doesn’t seem to recognise that my code is working.

I have attached my code below, please let me know if it is anything I have done myself, as I am confused…

var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var mongoose = require('mongoose')
var Schema = mongoose.Schema

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function() {
  console.log('Connected to MongoDB')

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

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

var person = new Person({name: 'Tom', age: 33, favoriteFoods: ['Rack of Lamb', 'Pulled Pork']});
console.log(person), data){
  if(err) return console.error(err)

Did you clone the glitch or github repos? I’m not sure how easy it will be to get the tests to pass if not. The first page of the challenges has links to both the glitch and github repos that have a lot of the testing code built in.

Am just working through these MongoDb and Mongoose challenges myself and find them incredibly hard to understand and very frustrating at how little guidance they give vs the rest of the curriculum :rage: (have completed the JS and Front End libraries certificates no problem). I’m literally just reading the Mongoose documentation and the Express tutorial on Mozilla Developer Network and using trial and error to try and figure out.

Anyway, I just managed to get this test to pass by adding a done() function at the end of the function:, data){
  if(err) return console.error(err);
  done(null, person);

I believe this returns null for ‘err’ and returns the person document as ‘data’ in the callback function. But maybe someone with more experience can give a better explanation :smiley:

Some of the lessons are kindof confusing. Earlier units really spell out what to do, but this unit requires a lot of trial-and-error, Googling, etc.

I’ve finished the lessons up to HelmetJS, but haven’t quite finished the projects yet. I’m having a lot of trouble figuring out how to console.log (to see what I’m doing in a live run), anything that involves connecting to a database, and a few other areas.

EDIT: Make sure you clone the original file. It seems to have part of the testing stored inside. Also the last 3 lessons in “Information Security with HelmetJS” use a different file than the first 11 or 12 lessons, so be aware of that.