You guys missed the rest of the discussion between CJ and I because he replied via email. I'll post it here...
So, first off, you can use Id instead of _id. We (C# driver) will map that by
default. In addition, you can use [BsonElement("username")] and name
your property with proper C# conventions. There is also a way to
configure this fluently or with conventions. I'd suggest you read the
serialization tutorial here:
http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial For your JsonWriter question, there is a Strict mode you can use with the JsonWriter in
order to get the MongoDBisms out of the way so things will go straight
into json properly. However, strict mode will not come back to
mongodb with some tweaking.
On Fri, Aug 31, 2012 at 10:52 PM, CJ <
carlo...@gmail.com> wrote:
> Just wanted to have a clean document and was wondering if that was
> possible...
>
> Another issue is i have the following scenario:
>
> public class User{
> public Guid _id { get; set; }
> public string username { get; set; }
> public string password { get; set; }
> public User(){
> _id = Guid.NewGuid();
> }
> }
>
> var user = new User();
>
> // With settings
> JsonWriterSettings settings = new JsonWriterSettings{OutputMode =
> JsonOutputMode.JavaScript };
> user.ToJson(settings);
> /*
> {
> "_id":{
> "$binary":"n2FLBkAkhEOCkX42BGXRqg==",
> "$type":"03"
> },
> "username":"",
> "password":""
> }
> */
> Is there a way that the _id is simply returned
> "_id":"3F2504E0-4F89-11D3-9A0C-0305E82C3301" so that i can use it nicely in
> javascript and the stored document has its _id field in its binary shorter
> counter part ? instead of plain string guid.