i need your help, i'm trying to link my mlab with my models but it's throwing me an error like this:
throw new TypeError('Undefined type
' + name + 'at
' + path + ^
TypeError: Undefined type undefined
at required
Did you try nesting Schemas? You can only nest using refs or arrays.
In my folder models i've got : const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProjectSchema = new Schema({ name: String,
email: String,
description: String,
image: {data: Buffer, contentType: String },
date: { type: Date, default: Date.now },
location: String, //{street: String, number: String, zip: String,
city: String, required: true},
fixedAmount: Number, required: true,
wantedAmount: Number,
receivedAmount: Number });
module.exports = mongoose.model('Project', ProjectSchema);
and almost the same with my UserSchema...
i have also an index.js there :
const mongoose = require('mongoose');
module.exports.connect = (uri) => {
mongoose.connect(uri);
// plug in the promise library:
mongoose.Promise = global.Promise;
mongoose.connection.on('error', (err) => {
console.error(Mongoose connection error: ${err}
);
process.exit(1); });
// load models
require('./user');
require('./project');
require('./common'); };
In my server.js :
const config = require('./config.js');
// connect to the database and load models
require('./server/models').connect(config.dbUrl);
and in my config.js:
const dotenv = require('dotenv').config();
module.exports = {
'port': process.env.PORT || 5000,
'dbUrl': mongodb://${process.env.USER_DB}:${process.env.PASSWORD_DB}@ds123930.mlab.com:23930/kickass
,
"jwtSecret": "a secret phrase !" }
Thanks
via P_Js
No comments:
Post a Comment