Mongoose.model is not a function

I know that this question was asked before, but none of the answers (or comments) helped me.

I have this error using the same code that works in another project, and I cannot understand why this is happening.

var mongoose = require('mongoose');

var objectSchema = new mongoose.Schema ({
    title: { type: String },
    img: { type: String },
    likes: { type: Number },
    profile: { type: String },
    username: { type: String }
});

module.exports = mongoose.model('Object', objectSchema);

When I mount the console log, it shows this (no model): console.log (mongoose)

I defined mongoose in app.js as below:

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/objectsdatabase');

I tried both mongoose 4.3.4 and 4.6.0.

Does anyone know how to solve this problem?

Thank.

+4
source share

Source: https://habr.com/ru/post/1655224/


All Articles