[SERVER-4708] "{ $pull : { field : _value } }" support removes the first occurrences of value from field, if field is an array. Created: 18/Jan/12 Updated: 06/Dec/22 Resolved: 13/Aug/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | 2.0.2 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | gavinliu | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | update | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
platform: redhat 6.1. mongodb version: 2.0.2 |
||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Query
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Participants: | |||||||||
| Description |
|
{ $pull : { field : _value } } will removes all occurrences of value from field, if field is an array. } removes the first occurrences of value from field. , {"name":"jhon"}, {"name":"gavin"}] |
| Comments |
| Comment by Asya Kamsky [ 22/Jan/14 ] | ||
|
As a work-around, it's possible to make a positional update to the item you want to remove (to make it unique) and then $pull by that attribute. Example:
If the element you want to remove happens to be first in array (like it is in this example) you ca use $pop operator with -1 (to remove one element from the front). |