我有两种不同的模式,我想将一个模式的特定字段(具有其自己的ObjectId)引用到另一种模式。
这是针对具有mongodb,mongoose,nodejs的Web应用程序。
#This is a Schema of Order#
var orderSchema = new Schema({
deliveryAddress: {
type: Schema.Types.ObjectId,
required: true,
ref: "user.address"//This is where I want to give ref of
//another schemas particular Object field
}
})
module.exports = mongoose.model("order", orderSchema);
##This is Schema of User##
var userSchema = new Schema({
address: [{
pincode: {
type: Number,
required: true
},
address: { //This Object fiels Id I want to give ref to
//another schema
type: String,
required: true
}
}] })
module.exports = mongoose.model("user", userSchema);
After populate of order I should get all details of respective
address