我正在使用mongoDB和node.js尝试创建两个模型应用程序和 contactsapp 之间的关系
applicationsModel
'use strict'
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const contactapp = mongoose.model('ContactApp');
const ApplicationsSchema = Schema({
application_code: String,
name: String,
comments: String,
version: String,
developer: String,
url: String,
active: Boolean,
press_package: String,
pad_file: String,
image: String,
category: [String],
contacts: [{ type: Schema.ObjectId, ref: "ContactApp" }]
});
module.exports = mongoose.model('Applications', ApplicationsSchema);
contactsappModel
'use strict'
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ContactappSchema = Schema({
fullname: String,
avatar: String,
company: String,
jobTitle: String,
email: String,
phone: String,
sex: String,
country: String,
channel: String,
website_url: String,
linkedin_url: String,
xing_url: String,
notes: String,
active: Boolean
});
module.exports = mongoose.model('ContactApp',ContactappSchema);
但是当控制台给我错误时,Schema尚未注册模型“ContactApp”。
答案 0 :(得分:0)
您的应用可能会在applicationsModel.js
之前加载contactsappModel.js
,因此执行此行时尚未注册ContactApp
模型:
const contactapp = mongoose.model('ContactApp');
由于您还没有使用contactapp
变量,请尝试完全删除该行。