我有一个有趣的用例,我正在处理它需要我将 Mongo 的 $unwind 运算符应用于两种数组类型(这是 mongo 文档中的一个属性)
这是一个示例,我希望过滤 2 种枚举类型 $host.config.storageDevice.scsiLun - enum("ssd","disk1","disk2") $host.config.storageDevice.scsiLun.capacity.block -范围(1000-100000)
我可以 $unwind 多个运算符并在单个聚合管道中过滤它们吗
db["XXXXXXX"].aggregate( { $unwind : { "$host.config.storageDevice.scsiLun", "$host.config.storageDevice.scsiLun.capacity.block" } },
{ $match : { "host.config.storageDevice.scsiLun.lunType" : "cdrom" , "host.config.storageDevice.scsiLun.capacity.block" : { $gte : 60000 } , "managedObject" : "host" } } ,
{ $project : { "host.name" : 1 , "host.config.storageDevice.scsiLun.devicePath" : 1 , "host.config.storageDevice.scsiLun.capacity.blockSize" : 1 , "host.config.storageDevice.scsiLun.capacity.block" : 1 , "host.config.storageDevice.scsiLun.ssd" : 1 , "host.config.storageDevice.scsiLun.uuid" : 1 , "host.config.storageDevice.scsiLun.lunType" : 1 , "_id" : 0 }} )
或者
我可以将复合聚合操作单元的结果链接到另一个聚合单元吗
db["XXXXXXX"].aggregate( { $unwind : "$host.config.storageDevice.scsiLun" },
{ $match : { "host.config.storageDevice.scsiLun.lunType" : "cdrom" , "managedObject" : "host" } } ,
{ $project : { "host.name" : 1 , "host.config.storageDevice.scsiLun.devicePath" : 1 , "host.config.storageDevice.scsiLun.capacity.blockSize" : 1 , "host.config.storageDevice.scsiLun.capacity.block" : 1 , "host.config.storageDevice.scsiLun.ssd" : 1 , "host.config.storageDevice.scsiLun.uuid" : 1 , "host.config.storageDevice.scsiLun.lunType" : 1 , "_id" : 0 }},
{ $unwind : "$host.config.storageDevice.scsiLun.capacity.blockSize" },
{ $match : { "host.config.storageDevice.scsiLun.capacity.blockSize" : { $gte : 8000000 } } },
{ $project : { "host.name" : 1 , "host.config.storageDevice.scsiLun.devicePath" : 1 , "host.config.storageDevice.scsiLun.capacity.blockSize" : 1 , "host.config.storageDevice.scsiLun.capacity.block" : 1 , "host.config.storageDevice.scsiLun.ssd" : 1 , "host.config.storageDevice.scsiLun.uuid" : 1 , "host.config.storageDevice.scsiLun.lunType" : 1 , "_id" : 0 }}