As far as I know there is not a directed way to do it but you can to use another way: Using aggregation stages into update
query:
The trick is to use $slice
. Check how it works here.
This example is concating two arrays, each array is using a different syntax, note that the documentation says:
$slice
Returns a subset of an array.
$slice
has one of two syntax forms:
The following syntax returns elements from either the start or end of the array:
{ $slice: [ <array>, <n> ] }
The following syntax returns elements from the specified position in the array:
{ $slice: [ <array>, <position>, <n> ] }
So, in this example:
- The first
$slice
is getting the elements from the start to the index.
- The second
$slice
is getting the elements from the index to the end.
If you concatenate these two arrays you get the same array without the index.
db.collection.update({
"_id": 1
},
[
{
"$set": {
"array": {
"$concatArrays": [
{
"$slice": [
"$array",
YOUR_INDEX
]
},
{
"$slice": [
"$array",
{
"$add": [
1,
YOUR_INDEX
]
},
{
"$size": "$array"
}
]
}
]
}
}
}
])
Example here