Why $in is much faster than $all?

前端 未结 2 1046
孤城傲影
孤城傲影 2021-01-28 02:30
db.tablebusiness.find({ \"LongitudeLatitude\" : { \"$nearSphere\" : [106.772835, -6.186753], \"$maxDistance\" : 0.053980478460939611 }, \"Prominent\" : { \"$gte\" : 15 }         


        
相关标签:
2条回答
  • 2021-01-28 02:35

    You are comparing apples with oranges. Both queries return different results. $all means that the field value should match all the inputs whereas $in means that the field value should match any one of the values. $all is and, $in is or.

    Combined with the $limit - the $all query will need to look at more documents to find the match as compared to in.

    0 讨论(0)
  • 2021-01-28 02:43

    I asked a similar question in Why using $all in mongodb is much slower?

    This time I use only one word. Hence, there should be no difference between $in and $all. They both are equivalent.

    Still $all is much slower.

    Turns out, per answer on that, there is a bug in mongodb itself.

    https://jira.mongodb.org/browse/SERVER-1748

    I guess I simply won't use $all at all until the problem is fixed.

    To all other answers, have you tried this your self?

    0 讨论(0)
提交回复
热议问题