I have this document and i need remove only 3 items with name "Test" using only 1 request.
{ "_id" : 1, "items" : ["Test, "Test", "Test", "Test", "Test", "Sword", "Sword]}
It must become { "_id" : 1, "items" : ["Test", "Test", "Sword", "Sword]}
after request.
2
Answers
Maybe something like this:
Explained:
Playground
You can use this aggregation to get the desired result. The query uses the
$reduce
Aggregate Array Operator to iterate over theitems
array, and discards the first 3 matching "Test" items.