Mongo sorted list complexity

99封情书 提交于 2020-01-06 13:00:27

问题


For the following sorted list:

{
   sorted_list : [{name : <string>,score : <Number>}]
}

What are the complexities of the following commands (in 'O' notations)?

Find:

collection.find( { _id: 1}, { sorted_list: { $slice: [ <skip>, <limit> ] } } )

Insert:

collection.update(
   { _id: 1 },
   {
     $push: {
       sorted_list: {
         $each: [ { name: 3, score: 8 }, { name: 4, score: 7 }, { name: 5, score: 6 } ],
         $sort: { score: 1 }
       }
     }
   }
)

Remove:

collection.update({"sorted_list.name": name},{ $pull: { "sorted_list.name": <name> } },{ multi: true });

EDIT

Let's assume ther following index exists:

{ "sorted_list.name" : 1}

来源:https://stackoverflow.com/questions/27917739/mongo-sorted-list-complexity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!