I am porting a network-oriented application from PostgreSQL to MongoDB. The application makes heavy use of the 'inet' and 'mac' data types, especially when searching for IP addresses in a netblock.
One could argue that IP Addresses can simply be stored and searched as strings, which is true. However, it becomes increasingly difficult when you throw in netmasks and IPv6. For example, the IPv6 address "FFAB::1234" is really "FFAB:0000:0000:0000:0000:0000:0000:1234", and both forms are acceptable string representations.
I could not find any plans for including this feature in MongoDB, so I decided to tackle it myself. The resulting work can be found at:
IpAddr - Contains an IPv4 or IPv6 address along with a netmask
Examples to try in the shell:
var ip4 = IpAddr("192.168.1.1")
ip4.mask = 16
ip4 = IpAddr("192.168.1.1/24")
var ip6 = IpAddr("1234::abcd");
ip6.mask = 64
var ip6 = IpAddr("1234::abcd/32");
ip6 = IpAddr("::192.168.1.1/16");
MacAddr - Contains a 6-octet Media Access Control Address (Ethernet hardware address)
var mac = MacAddr("00:23:45:ab:cd:ef");
var uuid = UUID("123456789abcdef12345678901234567");
The branch listed above includes the code changes against the latest master (as of 24 Jan 2011), plus unit tests in both dbtests/ and jstests/.