Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MongoDB indexed range query slower?
> db.ip_blocks.find({start_address: {$lte: 1665637698}, end_address: {$gte: 1665637698}}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 3662284,
"nscannedObjects" : 3662284,
"n" : 1,
"millis" : 2645,
"indexBounds" : {
}
}
> db.ip_blocks.ensureIndex({start_address: -1, end_address: 1})
> db.ip_blocks.find({start_address: {$lte: 1665637698}, end_address: {$gte: 1665637698}}).hint({start_address: -1, end_address: 1}).explain()
{
"cursor" : "BtreeCursor start_address_-1_end_address_1",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 4336,
"indexBounds" : {
"start_address" : [
[
1665637698,
-1.7976931348623157e+308
]
],
"end_address" : [
[
1665637698,
1.7976931348623157e+308
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment