简体   繁体   中英

Mongo aggregate query extremely slow

So, I'm running what I feel ought to be a relatively simple query. Essentially I'm just summing the length of all the lists in a particular field.

I have ~250k documents in the database, with each document being about 200kb. The query is shown below, a very basic aggregate, but it currently takes ~30min to run. Is there anything I could do to speed this up? It feels silly to me that summing 250k elements would take half an hour.

db.user_data.aggregate([{$group: {_id: null, count: {$sum: {$size: "$text"}}}}])

I'm running on an m3.large ec2 instance running 14.04 for specs.

You might try using $unwind , to see if it goes any faster that way:

db.user_data.aggregate([{$project:{text:1, _id:0}}, {$unwind:"$text"},
    {$group: {_id: null, count: {$sum: 1}}}])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM