【发布时间】:2014-05-28 09:53:31
【问题描述】:
在 MongoDB 2.6 中,我们可以使用 $position (http://docs.mongodb.org/master/reference/operator/update/position/) 修饰符在 document 中更新数组期间指定数组中的位置。但我想在 subdocument 中插入一个数组。
文档架构:
{
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 中可以吗?
【问题讨论】:
-
新运算符的良好使用示例
标签: mongodb mongoose mongodb-query