The problem with the request in MongoDB. It is necessary to update several data with one request. Here is an example request:
$coll -> update( array( array( 'article' => 100500 ), array( '$set' => array( 'a' => 555 ), '$pull' => array( 'arr' => array( 't' => array( '$lt': 20 ) ) ) ) ) );
Here is an example of the document itself:
{ article: 100500, a: 400, arr: [ { t: 30, b: 12, n: 90 }, { t: 10, b: 16, n: 60 } ] }
My request:
- Updates the value of
a
to555
. - Removes all elements of the
arr
array, wheret < 20
.
The essence of the question : It is necessary to update the values of b
in the mass arr
. That is, wherever n == 90
, the value of b
must be changed to 777
. How can this request be supplemented to “kill 3 birds with one stone”?
The result should be such a document:
{ article: 100500, a: 555, /* Тут было: 400 */ arr: [ { t: 30, b: 777, n: 90 }, /* Тут был элемент массива */ ] }