0

Problem:

My aggregate $graphLookup query is taking too long, specifically 5-6 minutes to find first, second and third degree connections for highly connected people like 'Superman', refer to point 2 below.

I am using the mongodb website graph example as inspiration for my schema design, mine is simpler you can view my data,schema and query here mongoplayground.net

Useful information

  1. Borrowing from the tutorial, a bi-directional node structure connects two people to each other. One node exists from 'superman' to 'lois', another node exists from 'lois' to 'superman'.

  2. My total collection document count is 6791, with "superman" count at 2868. db.getCollection("people").find({from: "superman"}).count() // 2868

  3. Every document in the collection has 3 additional fields, for brevity, I have replicated it just once in MongoPlayGround link, lines 6 - 8

  4. I have individual indexes on fields to and from

  5. I have a compound index on to and from

  6. Aggregate query uses {readPreference: 'secondaryPreferred', allowDiskUse: true}

  7. Using mongoDB Atlas 6.0.5 M10 cluster

  8. Collection is read often, written rarely

  9. Open to changing the schema design

user3524762
  • 582
  • 4
  • 15

0 Answers0