【发布时间】:2020-12-29 14:31:29
【问题描述】:
这是模式模型
const tokoSchema = new mongoose.Schema({
name: String
product: [{display: Boolean}]
}
所以,我想要的是通过product.display 过滤数据。当我使用toko.find({"product.display": true}) 过滤它时,它只显示具有product.display: true 的toko 列表,但我想要的是如果产品显示为假,它会继续显示toko 的_id 和name,产品数组为空@987654327 @。预期查询示例
// showing all tokos
[
{
_id: blabla
name: "test",
product: [{_id: blabla, display: true}], // filter display:true
},
{
_id: blabla,
name: "test",
product: [] // no product with display:true
}
]
toko.find({"product.display": true}) 查询示例
// not showing all tokos
[
{
_id: blabla
name: "test",
product: [{_id: blabla, display: true}]
},
]
有什么解决办法吗?我应该使用聚合吗?
【问题讨论】:
标签: mongodb mongoose mongodb-query aggregation-framework