The biggest difference is of course the destination storage and how you interact with it in the API. (I wrote about something similar here on StackOverflow as it related to DBRefs).
When using the C# driver (and plain-old-C#-objects), if you want to force the Id to be stored as an ObjectId
, you may need to use the BsonRepresentationAttribute
:
public class StackOverflow
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Name { get; set; }
}
Or if you want to keep your classes free of MongoDB attributes:
BsonClassMap.RegisterClassMap<StackOverflow>(cm => {
cm.AutoMap();
cm.IdMemberMap.SetRepresentation(BsonType.ObjectId);
});
I have used this technique a number of times successfully. When I don't explicitly set the _id
to a custom ID (a custom key of some sort), I always use the ObjectId
format as it's relatively small and unique (and is smaller than a UUID and also embeds creation time which is really nice sometimes).