2017-05-30 39 views
0

即時通訊新的MongoDB與工作和Node.js的IM試圖創造應用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); 

但當控制檯給我錯誤架構尚未註冊模型「ContactApp」。

回答

0

您的應用程序可能加載applicationsModel.jscontactsappModel.js之前,所以ContactApp模式已經在執行這條線還沒有登錄:

const contactapp = mongoose.model('ContactApp'); 

既然你不使用contactapp變量無論如何,嘗試刪除該行完全。

+0

非常感謝你是對的,就是這樣...... –