我的问题是我如何在代码的后半部分导出两者。将两个对象都包含在Schema中然后作为VendorSchema导出,这两个对象之间有什么好处?
将接触点模型注册到Mongo是否有好处?
const VendorSchema = new Schema(
{
name: {
type: String,
unique: true
},
contacts: [PointOfContact.schema],
purchaseOrders: [purchaseOrderRef]
},
{ collection: "vendors" }
);
/// -------- vendor.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const PointOfContactSchema = new Schema({
name: {
type: String
},
emailAddress: {
type: String
},
phoneNumber: {
type: String
}
});
module.exports = mongoose.model("pointofcontact", PointOfContactSchema);
// ------ refs.js
const mongoose = require("mongoose");
purchaseOrderRef = {
type: mongoose.Schema.Types.ObjectId,
ref: "purchaseOrder"
};
module.exports = purchaseOrderRef;