問題描述
Pymongo, truy vấn tổng hợp nào trong số các truy vấn tổng hợp này sẽ hoạt động tốt hơn (Pymongo, which of these aggregare query will perform better)
I have pasted here two pymongo aggregate queries, both will return the same result. I want to know, which one will perform better,
conditions in two match pipeline
db.bseadjprice.aggregate([
{"$match":{"scripcode":"533159"}} ,
{"$match":{"date":{"$in":dt}}},
{"$project":{"_id":0, "high":"$high", "low" : "$low"}}
])
conditions in single match pipeline
db.bseadjprice.aggregate([
{"$match":{"scripcode":"533159", "date": {"$in":dt}}},
{"$project":{"_id":0, "high":"$high", "low" : "$low"}}
])
Thanks in advance for your inputs.
參考解法
方法 1:
Two matches could prevent 1 event: If first match false ‑ second match wont do work. it could be faster in cycles or with big data and strong query.
(by John Prawyn、dikkini)