S
S
Sergey Beloventsev2019-08-17 09:24:00
Node.js
Sergey Beloventsev, 2019-08-17 09:24:00

How to connect related documents?

there are two
artist.js files in shemas folder

'use strict';

var Mongoose  = require('mongoose');
var categoryShema = require('category.js')

var artistSchema = new Mongoose.Schema({
    id:{type: Number,required:true},
    name:{type: String,required:true},
    description: String,
    created_at:{type:Date, default: Date.now},
    category:{type:Schema.Types.ObjectId, ref: 'categoryModel'}
});

var artistModel = Mongoose.model('artist', artistSchema);
module.exports = artistModel;

and categories.js
'use strict';
var Mongoose  = require('mongoose');

var categorySchema = new Mongoose.Schema({
    id:{type: Number},
    name:{type: String,required:true},
    description:{type: String},
    created_at:{type:Date, default: Date.now},
    title:{type:String},
    keywords:{type:String},

});

var categoryModel = Mongoose.model('category', categorySchema);
module.exports = categoryModel;

when restarting pm2. pm2 log gives error
Error: Cannot find module 'category.js'

The question is how to connect correctly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question