ipv6 storage in mongo

1,039 views
Skip to first unread message

Will

unread,
Jun 14, 2011, 12:42:37 PM6/14/11
to mongodb-user
I'm trying to store the value of an ipv6 address in mongo and because
of mongo's 64bit limitation I cannot. I need this number to remain in
number form because I am trying to query a number in the range of two
ipv6 addresses. Is there anyway to store the ipv6 address without
having to use two 64bit numbers?

Andreas Jung

unread,
Jun 14, 2011, 12:46:48 PM6/14/11
to mongod...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Will wrote:
> I'm trying to store the value of an ipv6 address in mongo and because
> of mongo's 64bit limitation I cannot.

Why don't you store it as string?

- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJN95B3AAoJEADcfz7u4AZjOgULv0/WGbn4KSQiTNWIgUdL1AFz
zvzMphvqbjVAp63KjPRO5iB4ko0jYG3eOTc9mtruTTeQPOGauGPiEscYDor1qlv8
cXdxAC8SwfzoVyN2pRgvT5rRGSD7kemXonr/Id73ajRtFnZumhGf4bU5rzOJt5I0
YmWsEha+gPy5ZS1fnlckfWOqS0dRyXzFjj2xcaaO/0QSITCx2CtqaUbTQg6czOmo
K2WXP8AMznij/2JE18fYsSEHZcJc4CKgY3LakSyCzIW20F4+6uWsOpDdjpADpBnD
XmoRjWZV4VC2knGvtp9u9cqIbcKcZD6NvIgIPoFvTVJ4Pkap12NagmhneqQWXz4A
7KvFCg2ZwHvItcvy2kYabwKI+dC/aBHVBd0wJ7I7Soksc/C6tWl1WpMxu0IAaXTM
c95RudSpEJyLYT2Rt7P4CNk/Qn8COYAzar0+vLbIRYR7nj3iEkSGtvl3e8NlHwKL
9BplgSbwzis4uxYnpDew9SfxTeFZJQw=
=JJk/
-----END PGP SIGNATURE-----

lists.vcf

Will Smith

unread,
Jun 14, 2011, 12:56:41 PM6/14/11
to mongod...@googlegroups.com
Because I need to figure out if it is within a range of Addresses. Storing it as a string would loose the ablity to do that.


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Andreas Jung

unread,
Jun 14, 2011, 1:02:37 PM6/14/11
to mongod...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Then store the integer value as string.

- -aj

Will Smith wrote:
> Because I need to figure out if it is within a range of Addresses.
> Storing it as a string would loose the ablity to do that.
>

> On Tue, Jun 14, 2011 at 12:46 PM, Andreas Jung <li...@zopyx.com
> <http://zopyx.com>> wrote:
>
>
>
> Will wrote:
>> I'm trying to store the value of an ipv6 address in mongo and because
>> of mongo's 64bit limitation I cannot.
>
> Why don't you store it as string?
>

> -aj

- --


You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com

<mailto:mongod...@googlegroups.com>.


To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com

<mailto:mongodb-user%2Bunsu...@googlegroups.com>.


For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.


> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

- --
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJN95QtAAoJEADcfz7u4AZjaiQLv21g6hgYml2xM6LYXMKVxH8h
D2FkVM+We5a8/aWGLcokGKaS5C+eNS2AmX6ANWgaWnr39QpN9XfieuOR7UPV4d1S
ir0Zel1qM4aWWlP6IJmlZg9AId0VUvUqTex6TbGZ9AvYB4wO5vDnb9RMXDTqYFay
uKHHa2//ZYRUoMHU39wQseGYrrQYyk1j91XWiEcU3TpKnQVL/tG8O64nB14WoLkI
u0C1QSyJAq5qKr4HQA8RcmysgQbmB9tlwp9zR4CmYRozPNdBloGKbEkwnFdw1/G5
IEAXv0I6c/w4cv5IL/ZVSiitaYt54eYtDcX9sxGQmgKwPYxhX1Y8aZkoecbRQjYU
9Cqd2Tdbqs8ffafl1a/AXHLIcwGAQP12TWoie2kbOE+XP9sLXJLnkn1yUYBF4bZU
m41PDb4AdEwSYTy2mdss3k4w77zyuNId2bCxdF8FSqhKMx0bavRYfvGnmMOyvh/s
p5vQt4BvWp5yMqF9bdcRpzYptoq5LdM=
=uf8e
-----END PGP SIGNATURE-----

lists.vcf

Will Smith

unread,
Jun 14, 2011, 1:16:14 PM6/14/11
to mongod...@googlegroups.com
Thats doesn't solve the problem because I need to determine if the inputed value is in the range of the two values in the database. If I store the values in the db as strings I cannot do this comparison(to my knowledge). Currently the number is 39 digits long which is over the 8 bit limit for ints and a float only stores 36 digits. The only path I see is to represent all the ipv6 addresses as two 64bit numbers.

D-72070 Tübingen        | Produce & Publish

www.zopyx.com           | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJN95QtAAoJEADcfz7u4AZjaiQLv21g6hgYml2xM6LYXMKVxH8h
D2FkVM+We5a8/aWGLcokGKaS5C+eNS2AmX6ANWgaWnr39QpN9XfieuOR7UPV4d1S
ir0Zel1qM4aWWlP6IJmlZg9AId0VUvUqTex6TbGZ9AvYB4wO5vDnb9RMXDTqYFay
uKHHa2//ZYRUoMHU39wQseGYrrQYyk1j91XWiEcU3TpKnQVL/tG8O64nB14WoLkI
u0C1QSyJAq5qKr4HQA8RcmysgQbmB9tlwp9zR4CmYRozPNdBloGKbEkwnFdw1/G5
IEAXv0I6c/w4cv5IL/ZVSiitaYt54eYtDcX9sxGQmgKwPYxhX1Y8aZkoecbRQjYU
9Cqd2Tdbqs8ffafl1a/AXHLIcwGAQP12TWoie2kbOE+XP9sLXJLnkn1yUYBF4bZU
m41PDb4AdEwSYTy2mdss3k4w77zyuNId2bCxdF8FSqhKMx0bavRYfvGnmMOyvh/s
p5vQt4BvWp5yMqF9bdcRpzYptoq5LdM=
=uf8e
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Karthik

unread,
Jun 14, 2011, 1:20:43 PM6/14/11
to mongodb-user
Hi Andreas,

So here's what we're trying to do:
We have a CIDR range of IP addresses - say,
"2001:0db9:85a3:0000:0000:8a2e:0370:7334/126".

We're storing this data to be able to query IPs within that range and
have it retrieve this document - say, "'2001:db9:85a3::8a2e:370:7335".
The current tack we're taking is to store the starting ip address and
the ending ip address of that CIDR range in it's equivalent number
format. (2001:db8:85a3::8a2e:370:7334, 2001:db8:85a3::8a2e:370:7337)
so that we can do a $gte, $lte search to retrieve the document.
This number is a 128-bit value though and we're having trouble storing
that in MongoDB because there's a restriction of 64-bits for it's
float format.

Is there a better way of doing this (perhaps storing as a binary
value)?

Thanks for your time,
Karthik

On Jun 14, 1:02 pm, Andreas Jung <li...@zopyx.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Then store the integer value as string.
>
> - -aj
>
>
>
>
>
>
>
>
>
> Will Smith wrote:
> > Because I need to figure out if it is within a range of Addresses.
> > Storing it as a string would loose the ablity to do that.
>
> > On Tue, Jun 14, 2011 at 12:46 PM, Andreas Jung <li...@zopyx.com
> > <http://zopyx.com>> wrote:
>
> > Will wrote:
> >> I'm trying to store the value of an ipv6 address in mongo and because
> >> of mongo's 64bit limitation I cannot.
>
> > Why don't you store it as string?
>
> > -aj
>
> - --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> <mailto:mongod...@googlegroups.com>.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> <mailto:mongodb-user%2Bunsu...@googlegroups.com>.
> For more options, visit this group athttp://groups.google.com/group/mongodb-user?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/mongodb-user?hl=en.
>
> - --
> ZOPYX Limited           | zopyx group
> Charlottenstr. 37/1     | The full-service network for Zope & Plone
> D-72070 T�bingen        | Produce & Publishwww.zopyx.com          |www.produce-and-publish.com
> - ------------------------------------------------------------------------
> E-Publishing, Python, Zope & Plone development, Consulting
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (Darwin)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iQGUBAEBAgAGBQJN95QtAAoJEADcfz7u4AZjaiQLv21g6hgYml2xM6LYXMKVxH8h
> D2FkVM+We5a8/aWGLcokGKaS5C+eNS2AmX6ANWgaWnr39QpN9XfieuOR7UPV4d1S
> ir0Zel1qM4aWWlP6IJmlZg9AId0VUvUqTex6TbGZ9AvYB4wO5vDnb9RMXDTqYFay
> uKHHa2//ZYRUoMHU39wQseGYrrQYyk1j91XWiEcU3TpKnQVL/tG8O64nB14WoLkI
> u0C1QSyJAq5qKr4HQA8RcmysgQbmB9tlwp9zR4CmYRozPNdBloGKbEkwnFdw1/G5
> IEAXv0I6c/w4cv5IL/ZVSiitaYt54eYtDcX9sxGQmgKwPYxhX1Y8aZkoecbRQjYU
> 9Cqd2Tdbqs8ffafl1a/AXHLIcwGAQP12TWoie2kbOE+XP9sLXJLnkn1yUYBF4bZU
> m41PDb4AdEwSYTy2mdss3k4w77zyuNId2bCxdF8FSqhKMx0bavRYfvGnmMOyvh/s
> p5vQt4BvWp5yMqF9bdcRpzYptoq5LdM=
> =uf8e
> -----END PGP SIGNATURE-----
>
>  lists.vcf
> < 1KViewDownload

Anders Jonsson

unread,
Jun 14, 2011, 1:43:08 PM6/14/11
to mongodb-user
Actually an IPv6 address is composed of two parts. A 64-bit network
part and a 64-bit local part.
I don't know your exact use case, but if you're just trying to find
what network the address belongs to it should be enough to compare the
network part (64 bits). Or you could store the address as two separate
int64 fields and compare them separately.

/Anders

Karthik

unread,
Jun 14, 2011, 2:00:38 PM6/14/11
to mongodb-user
Unfortunately, we'll need to do lookups with random ranges - so the
mask really could be anything (not just 64).
We'll just go with storing it as 2 separate values - it's a pity
MongoDB doesn't have native support for storing IPv6 addresses though.

Thanks again!

mcoolin

unread,
Jun 14, 2011, 2:07:24 PM6/14/11
to mongod...@googlegroups.com
Probably going to be a common problem over the next while as the transition occurs.

Michael Cohen

unread,
Jun 14, 2011, 4:30:21 PM6/14/11
to mongod...@googlegroups.com
As a previous poster has indicated you could store the interger
encoded to a binary string. You should still be able to use $gt and
$lt with a string. For example the number 0xFF10203040 can be encoded
to a binary string of "\xff\x10\x20\x30\x40". This is also true:

"\xff\x10\x20\x30\x39" < "\xff\x10\x20\x30\x40" < "\xff\x10\x20\x30\x41"

So you should be able to use string comparison just as well as integer
comparison - just convert the number you are trying to compare to a
string first. This should even work if you decide to store the number
converted to a hex encoded string but storage is less efficient.

Michael.

Reply all
Reply to author
Forward
0 new messages