Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

oivindberg
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
oivindberg
Full Stack JavaScript Techdegree Graduate 43,923 Points

Problem with mongoose-seeder

Hello, everyone!

Im in the beginning of project 11 on the Full Stack Javascript Techdegree. I'm having trouble using the mongoose-seeder package to get the information from data.json into the database.

Basically, this is what happens: I make sure to use the package after the database has started using the following code:

db.once('open', () => {
    console.log('Database connection successful');

  seeder.seed(data).then(function(dbData) {
      console.log(dbData);
  }).catch(function(err) {
      console.log(err);
  });
});

I then get this error:

TypeError: Cannot read property 'dropDatabase' of undefined

So, I read the docs again and adds the following object as the second argument to the seed() method.

{ dropDatabase: false }

That gets rid of the first error. But then I get this error: MissingSchemaError: Schema hasn't been registered for model "User".

I can not see how that makes sense. I have defined all the models in a models.js file that ends like this:

const User = mongoose.model('User', UserSchema);
const Course = mongoose.model('Course', CourseSchema);
const Review = mongoose.model('Review', ReviewSchema);

module.exports.User = User;
module.exports.Course = Course;
module.exports.Review = Review;

The models.js file is required in my app.js file at the top. I have defined the Schemas of course.

Anyone have any ideas as to what is going on here? Thanks in advance! :)