Mongo sorted list complexity

2019-09-04 11:52发布

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}

0条回答
登录 后发表回答