Mongodb:聚合在Node.js中执行的速度比在Shell中慢

时间:2018-10-24 13:30:06

标签: node.js mongodb

大家!我正在处理非常大的集合,并在MongoDB中使用长管道进行聚合请求。在Node.js中,我的查询执行了超过2分钟,实际上由于连接超时,我没有任何响应,但是在Studio3T中,同一查询的执行时间最长为15秒。是因为Nodejs驱动程序引起的问题吗?它会像往常一样慢吗? 这是我的查询:       const pipeline = [ { "$match": { "_id.addr": address } }, { "$unwind": "$value.data" }, { "$project": { "_id.addr": 1.0, "value.data": 1.0 } }, { "$group": { "_id": { "sender": "$_id.addr", "receiver": "$value.data.to", "token": { "$split": [ "$value.data.t", "_" ] }, "amount": "$value.data.a" } } }, { "$group": { "_id": { "sender": "$_id.sender", "receiver": "$_id.receiver", "token": "$_id.token" }, "count": { "$sum": 1.0 }, "amount": { "$sum": "$_id.amount" } } }, { "$group": { "_id": { "sender": "$_id.sender", "receiver": "$_id.receiver", "token": { "name": { "$arrayElemAt": [ "$_id.token", 0.0 ] }, "address": { "$arrayElemAt": [ "$_id.token", -1.0 ] } }, "amount": "$amount", "count": "$count" } } }, { "$lookup": { "from": "history_coins_USD", "localField": "_id.token.name", "foreignField": "name", "as": "price" } }, { "$project": { "_id": { "sender": 1.0, "receiver": 1.0, "token": 1.0, "amount": 1.0, "price": { "$arrayElemAt": [ "$price", 0.0 ] }, "count": 1.0 } } }, { "$project": { "_id": { "sender": 1.0, "receiver": 1.0, "token": 1.0, "amount": 1.0, "price": { "$arrayElemAt": [ "$_id.price.values", -1.0 ] }, "count": 1.0 } } }, { "$project": { "_id": { "sender": 1.0, "receiver": 1.0, "token": 1.0, "amount": 1.0, "price": { "$multiply": [ "$_id.amount", "$_id.price.close" ] }, "count": 1.0 } } } ]; response = await db.collection('mapReduce_address_cryptohound_eth_gas').aggregate(pipeline, { allowDiskUse: true }).toArray();

顺便说一句,如果我将Im放在管道$ sort的末尾,即使在studio3t中它也将永远执行...

0 个答案:

没有答案