Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 439
Ankush Srivastava Avatar asked Feb 13 '26 21:02

Ankush Srivastava


1 Answers

Please add this line in category.js pages top :

var mongoose = require('mongoose');
like image 200
Bilash Avatar answered Feb 15 '26 12:02

Bilash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!