如何在另一个模式猫鼬中获取一个模式的特定字段的引用?

时间:2019-11-10 19:54:06

标签: node.js mongodb mongoose mongoose-schema mongoose-populate

我有两种不同的模式,我想将一个模式的特定字段(具有其自己的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

0 个答案:

没有答案