Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Mongodb's generated UID contain the word "bad"

Mongodb's generated UID contain the word "bad"

Problem

Does anyone know what a "_id" generated by MongoDB ( or perhaps a Mongoose save ) means when it contains the word "bad" in the middle.

eg: 521b633274bad76823000002

I couldn't find an answer on the net or here.

This was happening on "save", but only discovered when I wanted to "update" the document. It would not allow an update.

 db.collection.update(...

The callback from the attempted 'updated' object was always null and the document was not updated.

Switching my database resolved the issue, so I am confident this is not in code ( and the code is very simple )

Using both mongojs and mongoose on Node.

Many Thanks,

Rob

Problem courtesy of: Rob Sedgwick

Solution

It doesn't mean anything.

The ObjectID is a hexadecimal string which can include the characters 0123456789abcdef. That means that any word which can be written with those 6 letters, like "bad", "beef", "dead", "deaf", "babe" or "cafe" has a certain probability to appear in them (for the exact probability, please consult our friends).

In your case, the string "bad" appears in the three bytes which are the machine-ID ("74bad7"), so all ObjectIDs created by the same machine will contain this 6-digit string. How the machine ID is generated depends on the driver, but usually it is created by using the first 6 digits of the MD5 hash of either the hostname or the MAC address. So when you don't want any more "bad" objectID's, experiment with changing those and brute-force them until you get one you like ;)

Your problem with updating your document must have some other reason, but the details you provided don't include a hint what the problem could be.

Solution courtesy of: Philipp

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Mongodb's generated UID contain the word "bad"

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×