So here is the scenario; I have data that needs to be imported into MongoDB that has a guid id. I'm using Ruby to import the data but the data will be consumed by a .NET app using NoRM. How do I represent that guid id in MongoDB and how do I work with it in Ruby and C# via NoRM? Easy. Here you can see the Ruby BSON Binary class enables you to work with binary data of a certain MongoDB sub type. The sub type that NoRM recognizes as a guid is UUID (Pretty obvious right? Don't say yes, I've been fighting with this for a couple of hours! :). So all you have to do is convert your guid into a binary type, with the UUID subtype specified, using the aforementioned class. Here is an example in Ruby (Noticed I've stripped the hyphens from the guid):

item = {"_id" =>"fd4fc014ef2d48b092ccf17208ee29eb", BSON::Binary::SUBTYPE_UUID), ... }

You can see what this looks like after it's been saved here in the MongoDB admin console:


The "3" in the BinData value is the MongoDB binary sub classification (Which in this case is UUID). Now this is exactly how NoRM persists .NET Guids in MongoDB. So on the .NET side just create a property on your entity called "Id" (Or _id) that is of type Guid and NoRM will take care of everything else.