BinData comparison

134 views
Skip to first unread message

Alexey Ivanov

unread,
Sep 30, 2011, 9:40:59 AM9/30/11
to mongod...@googlegroups.com
Hello.
I'm optimizing the space for my storage. So I found that the least integer stored in mongodb is 32 bit integer. But I have some properties which has few different values.
So I thought what if I replace 4 byte number with 1 bite BinData. It will reduce the storage size.
But also I need to perform search queries on mentioned fields. And I found nothing how BinData values are compared to each other.
Could someone, please, provide more info on this topic?

Thanks in advance,
    Alexey

Nat

unread,
Sep 30, 2011, 9:53:19 AM9/30/11
to mongod...@googlegroups.com
Did you check http://www.bsonspec.org. BinData actually takes more space than int32
From: Alexey Ivanov <lexa....@gmail.com>
Date: Fri, 30 Sep 2011 06:40:59 -0700 (PDT)
Subject: [mongodb-user] BinData comparison
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/1PrK6veEd5cJ.
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.

Scott Hernandez

unread,
Sep 30, 2011, 9:54:43 AM9/30/11
to mongod...@googlegroups.com
They are compared by their binary values, first the subtype, then payload.

It is not smaller than an 32bit int because of the subtype.

see http://bsonspec.org for how binary is stored.

Alexey Ivanov

unread,
Sep 30, 2011, 10:00:07 AM9/30/11
to mongod...@googlegroups.com
Thanks for the answers. I haven't checked spec :)

So there is no way to reduce the size of such kind values, isn't it? Every byte is important because I have more than 2B records in the collection.

Scott Hernandez

unread,
Sep 30, 2011, 10:08:03 AM9/30/11
to mongod...@googlegroups.com
Check the spec, all the sizes are there. Storing a large number of
bytes/ints can be more efficient as binary since it doesn't field
names or headers for each one.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/iCx-vxGM9sAJ.

Alexey Ivanov

unread,
Sep 30, 2011, 10:13:09 AM9/30/11
to mongod...@googlegroups.com
Thanks but I can't put several numbers in one binary property, because I need to query on that properties.
Reply all
Reply to author
Forward
0 new messages