Re-defining objectId for better shardability

5 views
Skip to first unread message

Georg Koester

unread,
Feb 25, 2012, 4:10:40 PM2/25/12
to mongodb-user
Hi all,

I was starting work on a new project and I would like to design
sharding into my setup from the start. Therefore I want to create my
own objectId with a month-prefix and a different order. I did some
development and can provide the code - basically used the bson
objectId Java class as template.

Could you hint how I can ensure that serialization uses the binary
format of objectids in the db?

Go mongo!
Georg

Scott Hernandez

unread,
Feb 25, 2012, 5:22:41 PM2/25/12
to mongod...@googlegroups.com

You cannot change the data in an objectid. It is a defined type. You can define your own binary field if you want, and store it as the _id field.

--
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.

Georg Koester

unread,
Feb 26, 2012, 7:46:40 AM2/26/12
to mongodb-user
Hi Scott,

thanks for the hint! I implemented that and It's quite ok. I
understand that there's a 4 byte overhead for the length attribute and
that I could rewrite my own object id generator with a different order
of the parts that are composed to the 12 byte id, too, if I wanted
better write distribution with smaller indexes/tables. I'm going to do
that, too. That'll be a nice id toolbox!

For reference: Digging deeper I found a very good discussion of the
topic in
http://groups.google.com/group/mongodb-user/browse_thread/thread/5108572d262e355f

Cheers all,
Georg


On 25 Feb., 23:22, Scott Hernandez <scotthernan...@gmail.com> wrote:
> You cannot change the data in an objectid. It is a defined type. You can
> define your own binary field if you want, and store it as the _id field.
Reply all
Reply to author
Forward
0 new messages