首页 > 解决方案 > 检索与数组中的值匹配的所有对象

问题描述

我试图获取与某个值匹配但它不起作用的所有匹配对象

这是我的 bd:

[1]:https://imgur.com/a/1RfMIvd

我的模型.js

var professorSchema = new schema({ 
nome : {type: String},
email : {type: String},
url : {type: String}
})

var aulaSchema = new schema ({
tipo : {type: String},
data : {type: String},
})

var sumarioSchema = new schema({
disciplina : {type: String},
professor : {professorSchema},
aula :[aulaSchema]
})

和我的controller.js

Sumarios.listAula = ()=>{
return Sumario.aggregate(
    // Start with a $match pipeline which can take advantage of an index and limit documents processed
    { $match : {
       "aula.tipo":"T"
    }},
    { $unwind : "$aula" },
    { $match : {
       "aula.tipo":"T"
    }}
  ).exec() 
}

我试图在控制器中执行的这个查询正在返回每个数据,而不是我想要的。我的模型有问题吗?

标签: node.jsmongoose

解决方案


推荐阅读