无法使用猫鼬返回选择子文档(数组)

时间:2018-07-15 09:11:31

标签: node.js mongodb mongoose

我有一个父模式和一个子模式。我用猫鼬写了一个查询,以返回提供者正在做的测试(我想通过匹配master_id来选择一个测试。

查询:

const pro =provider.find({'tests.master_id':test_id}); 
            pro.near('location.coordinates', { center: [long, lat], maxDistance: miles, spherical: true });
            pro.select('tests.$:1');
            pro.limit(10);
            pro.exec(function(err, prov1){

}

预期输出:

返回数组中的选定测试。

父模式:

var providerSchema = new mongoose.Schema({
    provider_type: String,
    name: String,
    tests: [testhistSchema],
   });

和TesthistSchema子模式

var testhistSchema = new mongoose.Schema({
    test_name: String,
    master_id: {type: mongoose.Schema.Types.ObjectId,
        ref: 'testSchema'
    }});

0 个答案:

没有答案