Users kept complaining about search performance. With customers managing 1000+ VMs, they were constantly searching:

  • VM by UUID: β€œ550e8400-e29b-41d4-a716-446655440000”
  • VM by name: β€œprod-database-01”
  • VM by IP: β€œ10.24.3.156”
  • Volume by UUID: β€œ7b3f6d2a-9c8e-4f5a-b1d2-3e4f5a6b7c8d”
  • Power host by hostname: β€œpower-host-dal-03”
  • Hypervisor hosts, network IDs…

Every. Single. Search. Was. A. Collection. Scan.

// What we were doing
db.vms.find({ $or: [
  { uuid: searchTerm },
  { name: searchTerm },
  { ip: searchTerm },
  { hostname: searchTerm }
]})
// Scanning 50k+ documents every time someone typed in the search box

The fix was actually simple:

// Individual indexes for each searchable field
db.vms.createIndex({ "uuid": 1 })
db.vms.createIndex({ "name": 1 })  
db.vms.createIndex({ "ip": 1 })
db.vms.createIndex({ "hostname": 1 })

// Same for other collections
db.volumes.createIndex({ "uuid": 1 })
db.hosts.createIndex({ "hostname": 1 })
db.hypervisors.createIndex({ "hostname": 1 })

Search went from 15 seconds to under 100ms. Users are happy and less complaints.