我有一个集合名称vehicle
。我将vehicle_type
存储在vehicle
模式中。我没有任何vehicle_type
收藏。
我创建了另一个集合名称driving_licence
。在此集合中,我存储了vehicle
和vehicle_type
ref
,并且我想填充这些vehicle
和vehicle_type
的细节。
车辆架构
var mongoose = require("mongoose"),
bcrypt = require("bcryptjs"),
Schema = mongoose.Schema;
var TypeSchema = new Schema({
title: { type: String, required: true },
status: { type: Boolean, default: true }
});
/**
* Vehicle Schema
*/
var VehicleSchema = new Schema(
{
title: {
type: String,
trim: true,
required: true
},
type: [TypeSchema],
status: { type: Boolean, default: true }
},
{
timestamps: {
createdAt: "created",
updatedAt: "updated"
},
id: false,
toJSON: {
getters: true,
virtuals: true
},
toObject: {
getters: true,
virtuals: true
}
}
);
VehicleSchema.index({ title: 1 });
module.exports.Vehicle = mongoose.model("Vehicle", VehicleSchema);
module.exports.Type = mongoose.model("Type", TypeSchema);
驾驶执照架构
var mongoose = require("mongoose"),
bcrypt = require("bcryptjs"),
Schema = mongoose.Schema;
const Type = require("../models/Vehicle.js").Type;
/**
* Vehicle Schema
*/
var DrivingLicenceSchema = new Schema(
{
title: {
type: String,
trim: true,
required: true
},
licence_type: [
{
vehicle: { type: Schema.Types.ObjectId, ref: "Vehicle" },
vehicle_type: [
{
_id: { type: Schema.Types.ObjectId, ref: "Type" },
status: { type: Boolean, default: true }
}
]
}
],
status: { type: Boolean, default: true }
},
{
timestamps: {
createdAt: "created",
updatedAt: "updated"
},
id: false,
toJSON: {
getters: true,
virtuals: true
},
toObject: {
getters: true,
virtuals: true
}
}
);
DrivingLicenceSchema.index({ title: 1 });
module.exports.DrivingLicence = mongoose.model(
"DrivingLicence",
DrivingLicenceSchema
);
请帮助我。