【发布时间】:2016-12-22 20:50:15
【问题描述】:
我的集合中有很多子文档,我只想获取对象的配置数组(非空)并忽略所有其他对象
我在stackoverflow上尝试了一种解决方案Find MongoDB records where array field is not empty (using Mongoose)
它返回配置数组以及我的集合中的其他对象
这里是样本数据
这个查询返回我所有的对象配置数组,但它也返回我不想要的空数组,有什么解决方案吗?
return Company.find({}, {
"configuration": 1
}, {
"configuration": {
"$not": {
"$size": 0
}
}
})
样本数据
configuration: [],
configuration: [],
configurtaion: [{
"id": "2013",
"name": "TRUEAUTO",
"locationId": null,
"deviceIdentifier": "850",
"serialNumber": "",
"modelNumber": "OptiPlex 3010",
"tagNumber": null,
"purchaseDate": null,
"installationDate": "2016-07-28T00:00:00.000Z",
"warrantyExpirationDate": null,
"vendorNotes": null,
"notes": null,
"lastLoginName": null,
"billFlag": "false",
"backupServerName": null,
"backupProtectedDeviceList": null,
}
}]
我想忽略空数组,只获取配置对象
【问题讨论】:
标签: mongodb subdocument