<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Getting started with MongoDB &#8211; Using Json.Net and Castle Dynamic proxy</title>
	<atom:link href="http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/feed/" rel="self" type="application/rss+xml" />
	<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/</link>
	<description>Love what you do - Continue to do it - Be eager to learn more about it.</description>
	<lastBuildDate>Sat, 21 Aug 2010 09:25:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy « Daniel Wertheim &#124; Head.SmackOnTable();</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-415</link>
		<dc:creator>Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy « Daniel Wertheim &#124; Head.SmackOnTable();</dc:creator>
		<pubDate>Sun, 06 Jun 2010 22:20:49 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-415</guid>
		<description>[...] Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy « Daniel Wertheim.   Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]</description>
		<content:encoded><![CDATA[<p>[...] Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy « Daniel Wertheim.   Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simple-MongoDB &#8211; Part 1, Getting started &#171; Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-250</link>
		<dc:creator>Simple-MongoDB &#8211; Part 1, Getting started &#171; Daniel Wertheim</dc:creator>
		<pubDate>Mon, 12 Apr 2010 12:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-250</guid>
		<description>[...] You have MongoDb up and running. If not, just go to &#8220;http://www.mongodb.org&#8221; and download the server part and start it. You can also read the first part of my earlier writings: Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy [...]</description>
		<content:encoded><![CDATA[<p>[...] You have MongoDb up and running. If not, just go to &#8220;http://www.mongodb.org&#8221; and download the server part and start it. You can also read the first part of my earlier writings: Getting started with MongoDB – Using Json.Net and Castle Dynamic proxy [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: My opinion on mappings for MongoDB &#171; Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-123</link>
		<dc:creator>My opinion on mappings for MongoDB &#171; Daniel Wertheim</dc:creator>
		<pubDate>Sat, 06 Mar 2010 18:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-123</guid>
		<description>[...] http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-... http://daniel.wertheim.se/2010/02/07/mongodb-in-c-extensions-to-support-json-mapping-or-proxy-generation/ http://automapper.codeplex.com/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-.." rel="nofollow">http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-..</a>. <a href="http://daniel.wertheim.se/2010/02/07/mongodb-in-c-extensions-to-support-json-mapping-or-proxy-generation/" rel="nofollow">http://daniel.wertheim.se/2010/02/07/mongodb-in-c-extensions-to-support-json-mapping-or-proxy-generation/</a> <a href="http://automapper.codeplex.com/" rel="nofollow">http://automapper.codeplex.com/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rei</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-99</link>
		<dc:creator>Rei</dc:creator>
		<pubDate>Mon, 15 Feb 2010 12:59:01 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-99</guid>
		<description>There is also an error when trying to serialize an object property which is not a simple type in the ToString method. It will generate the property as

&quot;Property&quot; : &quot;{&quot; &quot;Value&quot;: 1, &quot;Other&quot;: 2 &quot;}&quot;

Instead of:

&quot;Property&quot; : { &quot;Value&quot;: 1, &quot;Other&quot;: 2 }

I&#039;ll post these as issues to git hub. For the time being i&#039;ve used: 


 private static string ToInvariantString(this Document doc) {
            var json = new StringBuilder();
            json.Append(&quot;{ &quot;);
            var first = true;

            foreach (string key in doc.Keys) {
                if (first) {
                    first = false;
                } else {
                    json.Append(&quot;, &quot;);
                }
                json.AppendFormat(CultureInfo.InvariantCulture, @&quot;&quot;&quot;{0}&quot;&quot;: &quot;, key);
                SerializeType(doc[key], json);
            }
            json.Append(&quot; }&quot;);
            return json.ToString();
        }

        private static void SerializeType(object value, StringBuilder json) {
            if (value == null) {
                json.Append(&quot;null&quot;);
                return;
            }
            var t = value.GetType();
            if (value is bool) {
                json.Append(((bool)value) ? &quot;true&quot; : &quot;false&quot;);
            } else if (t.IsArray) {
                json.Append(&quot;[ &quot;);
                var first = true;
                foreach (var v in (Array)value) {
                    if (first) {
                        first = false;
                    } else {
                        json.Append(&quot;, &quot;);
                    }
                    SerializeType(v, json);
                }
                json.Append(&quot; ]&quot;);
            } else if (value is Document) {
                json.Append(((Document)value).ToInvariantString());
            } else if (value is Oid &#124;&#124;
                 value is int &#124;&#124;
                 value is Int32 &#124;&#124;
                 value is long &#124;&#124;
                 value is float &#124;&#124;
                 value is double) {
                json.AppendFormat(CultureInfo.InvariantCulture, &quot;{0}&quot;, value);
            } else if (value is DateTime) {
                json.AppendFormat(@&quot;&quot;&quot;{0}&quot;&quot;&quot;, ((DateTime)value).ToUniversalTime().ToString(&quot;o&quot;));
            } else {
                json.AppendFormat(CultureInfo.InvariantCulture, @&quot;&quot;&quot;{0}&quot;&quot;&quot;, value);
            }
            return;
        }

Which is about the same as the .ToString method on the document, with a few edits here and there :)

Hope this helps someone.</description>
		<content:encoded><![CDATA[<p>There is also an error when trying to serialize an object property which is not a simple type in the ToString method. It will generate the property as</p>
<p>&#8220;Property&#8221; : &#8220;{&#8221; &#8220;Value&#8221;: 1, &#8220;Other&#8221;: 2 &#8220;}&#8221;</p>
<p>Instead of:</p>
<p>&#8220;Property&#8221; : { &#8220;Value&#8221;: 1, &#8220;Other&#8221;: 2 }</p>
<p>I&#8217;ll post these as issues to git hub. For the time being i&#8217;ve used: </p>
<p> private static string ToInvariantString(this Document doc) {<br />
            var json = new StringBuilder();<br />
            json.Append(&#8220;{ &#8220;);<br />
            var first = true;</p>
<p>            foreach (string key in doc.Keys) {<br />
                if (first) {<br />
                    first = false;<br />
                } else {<br />
                    json.Append(&#8220;, &#8220;);<br />
                }<br />
                json.AppendFormat(CultureInfo.InvariantCulture, @&#8221;"&#8221;{0}&#8221;": &#8220;, key);<br />
                SerializeType(doc[key], json);<br />
            }<br />
            json.Append(&#8221; }&#8221;);<br />
            return json.ToString();<br />
        }</p>
<p>        private static void SerializeType(object value, StringBuilder json) {<br />
            if (value == null) {<br />
                json.Append(&#8220;null&#8221;);<br />
                return;<br />
            }<br />
            var t = value.GetType();<br />
            if (value is bool) {<br />
                json.Append(((bool)value) ? &#8220;true&#8221; : &#8220;false&#8221;);<br />
            } else if (t.IsArray) {<br />
                json.Append(&#8220;[ ");<br />
                var first = true;<br />
                foreach (var v in (Array)value) {<br />
                    if (first) {<br />
                        first = false;<br />
                    } else {<br />
                        json.Append(", ");<br />
                    }<br />
                    SerializeType(v, json);<br />
                }<br />
                json.Append(" ]&#8220;);<br />
            } else if (value is Document) {<br />
                json.Append(((Document)value).ToInvariantString());<br />
            } else if (value is Oid ||<br />
                 value is int ||<br />
                 value is Int32 ||<br />
                 value is long ||<br />
                 value is float ||<br />
                 value is double) {<br />
                json.AppendFormat(CultureInfo.InvariantCulture, &#8220;{0}&#8221;, value);<br />
            } else if (value is DateTime) {<br />
                json.AppendFormat(@&#8221;"&#8221;{0}&#8221;"&#8221;, ((DateTime)value).ToUniversalTime().ToString(&#8220;o&#8221;));<br />
            } else {<br />
                json.AppendFormat(CultureInfo.InvariantCulture, @&#8221;"&#8221;{0}&#8221;"&#8221;, value);<br />
            }<br />
            return;<br />
        }</p>
<p>Which is about the same as the .ToString method on the document, with a few edits here and there <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hope this helps someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-98</link>
		<dc:creator>Daniel Wertheim</dc:creator>
		<pubDate>Mon, 15 Feb 2010 12:40:12 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-98</guid>
		<description>Hi,

Post the issue at: http://github.com/samus/mongodb-csharp/issues

I&#039;m currently trying to get some time to build by own driver but I don&#039;t know if I will get enough time....

//Daniel</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Post the issue at: <a href="http://github.com/samus/mongodb-csharp/issues" rel="nofollow">http://github.com/samus/mongodb-csharp/issues</a></p>
<p>I&#8217;m currently trying to get some time to build by own driver but I don&#8217;t know if I will get enough time&#8230;.</p>
<p>//Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rei</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-97</link>
		<dc:creator>Rei</dc:creator>
		<pubDate>Sun, 14 Feb 2010 14:49:30 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-97</guid>
		<description>No there is only one other problem with the ToString method on the document... It takes into consideration the current culture, which in my case has &quot;,&quot; as the decimal separator and this obviously screws up the json format :/</description>
		<content:encoded><![CDATA[<p>No there is only one other problem with the ToString method on the document&#8230; It takes into consideration the current culture, which in my case has &#8220;,&#8221; as the decimal separator and this obviously screws up the json format :/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-96</link>
		<dc:creator>Daniel Wertheim</dc:creator>
		<pubDate>Fri, 12 Feb 2010 11:06:36 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-96</guid>
		<description>Hi!

The issue has been corrected in Oid.ToString in the MongoDb-driver, but Sam was uncertain if it had reached the main-branch at Github.

Nice tip with the nested types.

//Daniel</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>The issue has been corrected in Oid.ToString in the MongoDb-driver, but Sam was uncertain if it had reached the main-branch at Github.</p>
<p>Nice tip with the nested types.</p>
<p>//Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rei</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-95</link>
		<dc:creator>Rei</dc:creator>
		<pubDate>Fri, 12 Feb 2010 10:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-95</guid>
		<description>Yes thanks Daniel, it works nicely now. The problem apparently is that I was using the driver from git which retrieves the oids as numbers. 

Now, regarding the storing of arrays,

In the 
protected virtual object ConvertToMongoDbValue(JToken token)
 if (token.Type == JTokenType.Array)
            {
                var r = token.Select(j =&gt; (string)j).ToArray();
                if (r == null &#124;&#124; r.Length &lt; 1)
                    return MongoDBNull.Value;

                return r;
            }

You could change it to:

if (value.Type == JTokenType.Array) {
                var items = new List();

                foreach (var v in value) {
                    var doc = PopulateDocumentFrom(new Document(), v.ToString());
                    items.Add(doc);
                }

                if (items.Count &lt; 1)
                    return MongoDBNull.Value;

                return items.ToArray();
            }

Giving you the ability to store/retrieve nested types :)</description>
		<content:encoded><![CDATA[<p>Yes thanks Daniel, it works nicely now. The problem apparently is that I was using the driver from git which retrieves the oids as numbers. </p>
<p>Now, regarding the storing of arrays,</p>
<p>In the<br />
protected virtual object ConvertToMongoDbValue(JToken token)<br />
 if (token.Type == JTokenType.Array)<br />
            {<br />
                var r = token.Select(j =&gt; (string)j).ToArray();<br />
                if (r == null || r.Length &lt; 1)<br />
                    return MongoDBNull.Value;</p>
<p>                return r;<br />
            }</p>
<p>You could change it to:</p>
<p>if (value.Type == JTokenType.Array) {<br />
                var items = new List();</p>
<p>                foreach (var v in value) {<br />
                    var doc = PopulateDocumentFrom(new Document(), v.ToString());<br />
                    items.Add(doc);<br />
                }</p>
<p>                if (items.Count &lt; 1)<br />
                    return MongoDBNull.Value;</p>
<p>                return items.ToArray();<br />
            }</p>
<p>Giving you the ability to store/retrieve nested types <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-94</link>
		<dc:creator>Daniel Wertheim</dc:creator>
		<pubDate>Wed, 10 Feb 2010 18:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-94</guid>
		<description>Hi!

I have just tested the following:

1. Downloaded my example from: http://files.wertheim.se/blog/Pls-Mdb-Intro.zip
2. Unziped
3. Opened in Visual Studio 2010
4. Started Mongodb (mongod -dbpath c:\MongoDB\Data -directoryperdb)
5. Ran the Pls.MdbIntro app (F5)
6. Worked without any exceptions.

Worked.

//Daniel</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I have just tested the following:</p>
<p>1. Downloaded my example from: <a href="http://files.wertheim.se/blog/Pls-Mdb-Intro.zip" rel="nofollow">http://files.wertheim.se/blog/Pls-Mdb-Intro.zip</a><br />
2. Unziped<br />
3. Opened in Visual Studio 2010<br />
4. Started Mongodb (mongod -dbpath c:\MongoDB\Data -directoryperdb)<br />
5. Ran the Pls.MdbIntro app (F5)<br />
6. Worked without any exceptions.</p>
<p>Worked.</p>
<p>//Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Wertheim</title>
		<link>http://daniel.wertheim.se/2010/02/05/getting-started-with-mongodb-using-json-net-and-castle-dynamic-proxy/#comment-92</link>
		<dc:creator>Daniel Wertheim</dc:creator>
		<pubDate>Wed, 10 Feb 2010 17:20:40 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.wertheim.se/?p=274#comment-92</guid>
		<description>Hi!
I have sent you an email so that you can send me your code.

Do that and I will check it out.

//Daniel</description>
		<content:encoded><![CDATA[<p>Hi!<br />
I have sent you an email so that you can send me your code.</p>
<p>Do that and I will check it out.</p>
<p>//Daniel</p>
]]></content:encoded>
	</item>
</channel>
</rss>
