如何在MongoDB中的where条件下基于引用的文档详细信息获取父文档详细信息?

时间:2018-07-11 09:48:47

标签: mongodb mongoose

我有两个如下文件。

const ClaimDetailsSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    benefitArea: String,
    gfo: String,
    productForm: String,
    type: String,
    status: String,
    claimTitle: String,
    claimId: String,
    claimName: String,
    exception: String,
    createdBy: String,
    createdByNtId: String,
    lastModifiedBy: String,
    claimType: {
        historyId: String,
        commentId: String,
        exportId: String,
        version: String,
        reason: String
    },
    Substantiations: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Substantiations' }],
    Formulaes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Formulaes' }],
    regions: [String],
    favorites: [String],
    claimCreatedDate: { type: Date, default: Date.now },
    lastModifiedDate: { type: Date }
});

module.exports = mongoose.model('ClaimDetails', ClaimDetailsSchema);

const mongoose = require('mongoose'), Schema = mongoose.Schema;

const SubstantiationSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    substantiation: String
});

module.exports = mongoose.model('Substantiations', SubstantiationSchema);

我需要基于where子句中的证明文本来获取ClaimDetails。

我尝试过以下方法,但是没有运气。

exports.testCase = (req, res) => {
    Claimdetails.find().populate({ path: 'Substantiations', match: { substantiation: 'rel' } }).exec(function (err, claims) {
        res.send({ data: claims });
    });
};

0 个答案:

没有答案