我是个新手,请耐心等待。我想将这个robomongo查询转换为mongoid查询:
db.getCollection('products').find({'images':{$size:0},
$or:[
{'inventory.a':{'$gt':0}},
{'inventory.b':{'$gt':0}}
]
})
下面是我现在看到的,它抛出了一个错误Can't canonicalize query: BadValue $or needs an array
:
$products = Product::where([
'images' => [ '$size' => 0 ],
'$or' => [
'inventory.a' => ['$gt' => 0],
'inventory.b' => ['$gt' => 0]
]
]);
$or
:的内部键周围缺少括号
$products = Product::where([
'images' => [ '$size' => 0 ],
'$or' => [
[ 'inventory.a' => ['$gt' => 0] ],
[ 'inventory.b' => ['$gt' => 0] ]
]
]);
MongoDB表示法是"对象"的"列表",而不是您所表示的"带有多个键的单个对象"。
当与JSON进行比较时,您应该转储JSON编码以检查:
echo json_encode($query, JSON_PRETTY_PRINT);
通过这种方式,您可以发现在表示结构的方式上的差异。