1
推動元件在陣列的任何位置在MongoDB中2.6我們可以使用$position
(http://docs.mongodb.org/master/reference/operator/update/position/)修飾符指定在文檔陣列的更新期間的陣列中的位置。但我想插入一個子文檔的數組中。在子文檔
文檔模式:
{
subdoc: {
array: ['0', '1', '2', '5', '6']
}
}
以下更新推在array
末的元素..
db.collection.update(
{ _id: tsId },
{$push: { 'subdoc.array': { $each:['3', '4'], $position:3 } }});
所以,結果是
{
subdoc: {
array: ['0', '1', '2', '5', '6', '3', '4']
}
}
但我希望
{
subdoc: {
array: ['0', '1', '2', '3', '4', '5', '6']
}
}
在MongoDB 2.6中可能嗎?
新操作符的良好用法示例 –