mongodb - Lookup Operation Slow -


i have following query:

query = [{     $match: {       $and: [{         feed: {           $in: feeds         }       }, {         updatedat: {           $gte: new date(date)         }       }     ]     }   },   {     $lookup: {       from: "feed",       localfield: "feed",       foreignfield: "_id",       as: "feed"     }   },   {     $unwind: {       path: "$feed",       preservenullandemptyarrays: true     }   },   {     $lookup: {       from: "source",       localfield: "feed.source",       foreignfield: "_id",       as: "feed.source",     }   },   {     $sort: {       updatedat: -1     }   },   {     $limit: limit   },   {     $skip: skip   } ]; 

the query taking long, 10 seconds specific.

i read https://docs.mongodb.com/manual/core/aggregation-pipeline-optimization/ still rather slow.

i looking optimize as possible, there way? collection indexed $updatedat: -1

any ideas?

if want run fast i'd advise removing $lookup pipeline stages , modeling document based on usage.

you add index on first match part of aggregation query (updatedat, feed). you'll still have problem still looking 2 other collections wont use indexes.

the $match , $sort pipeline operators can take advantage of index when occur @ beginning of pipeline.

https://docs.mongodb.com/master/core/aggregation-pipeline/#pipeline-operators-and-indexes


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -