Good day

The structure of the entry in the collection:

{ "_id": ObjectId("577e3c801da29a8f2f8b4567"), "contacts": [ { "id": NumberInt(7) }, { "id": NumberInt(8) } ], "user": NumberInt(8) } 

It is necessary to remove in all entries from the array of contacts, an object with a specific id.

In Mongo, the problem is solved by such a request (for id = 7):

 db.perimeter.update({ }, {$pull: {contacts: {id:7}}}, {multi: true}) 

What is the syntax for the implementation of this task by means of the yii2-mongodb extension?

    1 answer 1

     return $this->updateAll( [ '$pull' => ['contacts' => ['id' => ['$in' => $contactIds] ] ] ], [ 'user' => $this->user ] ); 

    Where $ contactIds is an array of id-names to delete objects (with these id) from contacts.