小编ter*_*ter的帖子

如何从mongodb数组中删除前n个元素?

我在mongodb有这样的文件:

{uid:1212, outbox:
 [
   {msg1},
   {msg2},
   {msg3},
   ...
   {msgN}
 ]
}
Run Code Online (Sandbox Code Playgroud)
I want atomically remove first n elements from array outbox.

I know two ways to remove element from array
1) $pop
  But it removes only one element
2) {$unset:{outbox.0:1}}  after {$pull:{outbox:null}}
  But it non atomic and removes only one element

更新目前 这是不可能的

mongodb

5
推荐指数
1
解决办法
1558
查看次数

标签 统计

mongodb ×1