I want to execute Document Nested in an Array queries with the Doctrine mongodb odm query builder
I have basically a structure similar to :
db.inventory.insertMany( [
{ item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] },
{ item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },
{ item: "postcard", instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
]);
I want to execute this shell query within the query builder
db.inventory.find( { "instock": { warehouse: "A", qty: 5 } } )
I have tried this, but this won't work as it ignores the field 'instock'.
$qb->field('instock')->field('warehouse')->equals('A')->field('qty')->equals(5)
Keep in mind that doing the following
$qb->field('instock.warehouse')->equals('A')->field('instock.qty')->equals(5)
is a different logic (check second example), because it matches not necessarily the same embedded document.
I can implement it using $where and a loop, but it is ugly and slow. any better ideas ?