Ankush Srivastava
Ankush Srivastava

Reputation: 502

Getting mongoose not defined error in model file

mongoose module already installed also included in index.js

In index.js

mongoose = require('mongoose').connect(config.dbURL),
...
require('./routes/routes.js')(express, app);

In routes.js

var Category = require('../models/category');
...

Within model folder category.js

var categorySchema = mongoose.Schema({
        category_name:String,
        alias:String,
        added_on:String
    });

but error occurred while using in model file.

Folder structure:

server
-> index.js
-> routes/routes.js
-> models/category.js

enter image description here

Upvotes: 3

Views: 464

Answers (1)

Md Nazmul Hossain
Md Nazmul Hossain

Reputation: 2923

Please add this line in category.js pages top :

var mongoose = require('mongoose');

Upvotes: 2

Related Questions