I am building a ipv4/ipv6 geo ip MongoDB database and i will have millions (100+) of ips
Structure will of the database will be
[
{ _id: 58fdbf5c0ef8a50b4cdd9a8e , ip: '34.53.63.25', ip_hex: '0x22353f19' , type: "ipv4", data : [
{
country : "CA",
region : "region1"
city : "city1",
blacklisted : "no"
on_date : ISODate("2022-05-05T00:00:00Z")
},
{
country : "CA",
region : "region1"
city : "city1",
blacklisted : "yes"
on_date : ISODate("2022-06-05T00:00:00Z")
},
{
country : "US",
region : "region2"
city : "city2",
blacklisted : "no"
on_date : ISODate("2022-05-05T00:00:00Z")
},
...
]},
{ _id: 58fdbf5c0ef8a50b4cdd9a8e , ip: '1.2.3.4', ip_hex: '0x1020304', type: "ipv4", data : [
{
country : "CA",
region : "region1"
city : "city1",
blacklisted : "no"
on_date : ISODate("2022-06-05T00:00:00Z")
},
]},
{ _id: 58fdbf5c0ef8a50b4cdd9a8e , ip: '2345:0425:2CA1:0000:0000:0567:5673:23b5', ip_hex: '0x234504252ca1000000000567567323b5', type: "ipv6", data : [
{
country : "FR",
region : "region1"
city : "city1",
blacklisted : "no"
on_date : ISODate("2022-06-05T00:00:00Z")
},
{
country : "FR",
region : "region1"
city : "city1",
blacklisted : "yes"
on_date : ISODate("2022-07-05T00:00:00Z")
},
...
]},
]
I am converting all IP string data to HEX :
1.1.1.1 -> 0x1010101
1.2.3.4 -> 0x1020304
34.53.63.25 -> 0x22353f19
255.255.255.255 -> 0xffffffff
0001:0001:0001:0001:0001:0001:0001:0001 -> 0x10001000100010001000100010001
1111:1111:1111:1111:1111:1111:1111:1111 -> 0x11111111111111111111111111111111
2345:0425:2CA1:0000:0000:0567:5673:23b5 -> 0x234504252ca1000000000567567323b5
2345:0425:2CA1::0567:5673:23b5 -> 0x234504252ca1000000000567567323b5
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff -> 0xffffffffffffffffffffffffffffffff
There will be a lot of searches by IP and it will be added/deleted/updated new data to every IP each day.
I will search ranges of ips, sort, update, delete.
What index is recommended on "ip_hex" column? I was thinking about a B-tree search on HEX not STR.
I want to have an efficient database. What other optimizations should i take into consideration?
Thank you.