How to get machine id

504 views
Skip to first unread message

Alex.yu

unread,
Sep 5, 2010, 8:08:03 AM9/5/10
to mongodb-user
In my application I have to decide the machine id before I use mongodb
id. How can I do that? Is it a part of the has of something that
uniquely identifies a machine?

Kristina Chodorow

unread,
Sep 5, 2010, 9:22:17 AM9/5/10
to mongod...@googlegroups.com
If your driver follows the spec (all the official ones should), you can generate an ObjectId and the machine id will be the 9th-14th characters of its string representation.




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


Eliot Horowitz

unread,
Sep 5, 2010, 10:57:36 PM9/5/10
to mongod...@googlegroups.com
Just to clarify - are you writing your own driver or using an existing one?
If using an existing one, they should do this for you.

On Sun, Sep 5, 2010 at 8:08 AM, Alex.yu <vit...@gmail.com> wrote:

Alex yu

unread,
Sep 6, 2010, 7:55:05 AM9/6/10
to mongodb-user

I know it's 9th-14th characters. What I really want to know is how mongodb calculate this 6 characters. So I can use it  even before
the emergence of mongodb id.

Kyle Banker

unread,
Sep 6, 2010, 9:13:14 AM9/6/10
to mongod...@googlegroups.com
Here's how it's calculated in Ruby:

Digest::MD5.digest(Socket.gethostname)[0, 3]

All the other drivers will have a similar line of code.
Reply all
Reply to author
Forward
0 new messages