[英]How to encapsulate multiple $in queries in mongodb php
Here PRODUCT_NAME
and BRAND_NAME
are two different columns from same document.这里PRODUCT_NAME
和BRAND_NAME
是同一文档中的两个不同列。 And I want to apply a filter on the selected product and brand names.我想对选定的产品和品牌名称应用过滤器。
My array is something like this我的数组是这样的
Array
(
[PRODUCT_NAME] => Array
(
[$and] => Array
(
[$in] => Array
(
[0] => Product1
[1] => Product2
)
)
)
[BRAND_NAME] => Array
(
[$and] => Array
(
[$in] => Array
(
[0] => Brand1
)
)
)
)
The way to do this with mongodb ( assuming last version ) is to use mongodb aggregation and in particular $unwind使用 mongodb (假设是最新版本)执行此操作的方法是使用 mongodb 聚合,特别是$unwind
So as example in your case:所以作为你的例子:
db.yourcollection.aggregate( [
{ $unwind : "$firstattribute" } , // 1
{ $unwind : "$PRODUCT_NAME" }, // 2
{ $unwind : "$BRAND_NAME" }, // 3
] )
Now some explanation:现在做一些解释:
Note: I can provide a better (and runnable) solution with a real example ( a json with at least 2 elements in each array注意:我可以通过一个真实示例提供更好(且可运行)的解决方案(一个 json,每个数组中至少有 2 个元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.