정의
$pullAllThe
$pullAlloperator removes all instances of the specified values from an existing array. Unlike the$pulloperator that removes elements by specifying a query,$pullAllremoves elements that match the listed values.The
$pullAlloperator has the form:{ $pullAll: { <field1>: [ <value1>, <value2> ... ], ... } } 내장된 문서나 배열에
<field>기호를 지정하려면 점 표기법을사용하십시오.
행동
MongoDB 5.0부터 업데이트 연산자는 문자열 기반 이름이 있는 문서 필드를 사전순으로 처리합니다. 숫자 이름이 있는 필드는 숫자 순서대로 처리됩니다. 자세한 내용은 업데이트 운영자 동작을 참조하십시오.
If a <value> to remove is a document or an array, $pullAll removes only the elements in the array that match the specified <value> exactly, including order.
Starting in MongoDB 5.0, mongod no longer raises an error when you use an update operator like $pullAll with an empty operand expression ( { } ). An empty update results in no changes and no oplog entry is created (meaning that the operation is a no-op).
예시
survey 컬렉션을 생성합니다.
db.survey.insertOne( { _id: 1, scores: [ 0, 2, 5, 5, 1, 0 ] } )
다음 작업은 scores 배열에서 "0" 및 "5" 값의 모든 인스턴스를 제거합니다.
db.survey.updateOne( { _id: 1 }, { $pullAll: { scores: [ 0, 5 ] } } )
업데이트 후에는 scores 필드에 더 이상 "0" 또는 "5" 인스턴스가 없습니다.
{ "_id" : 1, "scores" : [ 2, 1 ] }