【问题标题】:Pymongo, which of these aggregare query will perform betterPymongo,这些聚合查询中的哪一个会执行得更好
【发布时间】:2013-03-03 18:16:41
【问题描述】:

我在这里粘贴了两个 pymongo 聚合查询,它们都将返回相同的结果。 我想知道,哪个会更好,

两个匹配管道中的条件

db.bseadjprice.aggregate([
            {"$match":{"scripcode":"533159"}} ,
            {"$match":{"date":{"$in":dt}}}, 
            {"$project":{"_id":0, "high":"$high", "low" : "$low"}}
        ])

单个匹配管道中的条件

db.bseadjprice.aggregate([
        {"$match":{"scripcode":"533159", "date": {"$in":dt}}}, 
        {"$project":{"_id":0, "high":"$high", "low" : "$low"}}
    ])

提前感谢您的意见。

【问题讨论】:

  • 您是否尝试过使用 $explain (docs.mongodb.org/manual/reference/operator/explain) 来查看它在做什么?您没有提到索引的内容。最好的答案来自于做真实的测试。为什么不只使用find 而不是aggregate
  • 不,我没有尝试过 $explain。谢谢。会尝试让您知道。
  • 您为什么使用aggregate 而不仅仅是find

标签: mongodb pymongo aggregation-framework


【解决方案1】:

两个匹配项可以阻止 1 个事件: 如果第一个匹配错误 - 第二个匹配将不起作用。它可能在循环或大数据和强查询时更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多