<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vance Lucas &#187; NoSQL</title>
	<atom:link href="http://www.vancelucas.com/blog/category/nosql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vancelucas.com</link>
	<description>Web Entrepreneur and Freelance PHP/Javascript Developer</description>
	<lastBuildDate>Thu, 17 Nov 2011 15:30:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MongoDB Gotchas</title>
		<link>http://www.vancelucas.com/blog/mongodb-gotchas/</link>
		<comments>http://www.vancelucas.com/blog/mongodb-gotchas/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 17:37:10 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=562</guid>
		<description><![CDATA[Most developers are coming from a background with relational database-specific experience, and then trying out some new NoSQL databases like MongoDB. Here are some &#8220;gotchas&#8221; I ran into while using MongoDB with my MySQL hat still on. Queries are case-sensitive Fields and queries in MongoDB are case-sensitive: 1 2 3 var test1 = db.test.find&#40;&#123;'tags': 'jquery'&#125;&#41;.count&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Most developers are coming from a background with relational database-specific experience, and then trying out some new NoSQL databases like <a href="http://mongodb.org">MongoDB</a>. Here are some &#8220;gotchas&#8221; I ran into while using MongoDB with my MySQL hat still on.<span id="more-562"></span></p>
<h3>Queries are case-sensitive</h3>
<p>Fields and queries in MongoDB are case-sensitive:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> test1 <span style="color: #339933;">=</span> db.<span style="color: #660066;">test</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'tags'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> test2 <span style="color: #339933;">=</span> db.<span style="color: #660066;">test</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'tags'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jQuery'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
test1 <span style="color: #339933;">==</span> test2<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Output is false - they do not query for the same information</span></pre></td></tr></table></div>

<p>This can cause some headaches if you don&#8217;t normalize user input ahead of time. Imagine you already have several posts tagged with &#8216;NoSQL&#8217; and users enter &#8216;nosql&#8217; in a tag search box. If you don&#8217;t normalize how the data is stored internally (like lowercase all tags), your user will see a much smaller set of posts than they are expecting to see. This is something you don&#8217;t have to worry or even think about with MySQL and most other relational databases.</p>
<p>If you can&#8217;t normalize the stored data, but still want a case-insensitive query, then you must perform a slower <a href="http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions">regular expression query</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">db.<span style="color: #660066;">test</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'tags'</span><span style="color: #339933;">:</span> <span style="color: #339933;">/</span>jquery<span style="color: #339933;">/</span>i<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Note the 'i' flag for case-insensitive</span></pre></td></tr></table></div>

<h3>Data is type-sensitive</h3>
<p>Data stored within MongoDB knows it&#8217;s type. There is a small but significant difference between these two records:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'count'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">102</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 'count' is stored as an int</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'count'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;102&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 'count' is stored as a string</span></pre></td></tr></table></div>

<p>This is obvious to any programmer when presented like this, but what may not be obvious is that this also affects how you can query for these records:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// This returns 1 instead of 2, because it only matches the integer value</span>
db.<span style="color: #660066;">test</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'count'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">102</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is due to how MongoDB stores documents internally with <a href="http://bsonspec.org/">BSON</a> (Binary JSON), using various <a href="http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions">MongoDB data types</a>. This means &#8211; like the point above &#8211; that you must pay attention to how you are saving data <em>into</em> MongoDB, because it will affect how you can query for it later.</p>
<h3>Documents sizes are capped at 4MB each</h3>
<p>This isn&#8217;t a big issue for most people, but it&#8217;s something to be aware of if you plan on storing large chunks of text or nesting a bunch of objects inside a single document. <a href="http://www.businessinsider.com/how-we-use-mongodb-2009-11">Nesting comments inside article documents</a> is a particular approach that may give you pause knowing there is an upper threshold on document size.</p>
<p>Note that this limitation is not an issue for storing <em>files</em> in MongoDB because <a href="http://www.mongodb.org/display/DOCS/GridFS">GridFS</a> transparently divides the contents of files larger than 4MB across multiple documents.</p>
<h3>Only one index is used per query</h3>
<p>Simply adding more indexes doesn&#8217;t always help queries run faster. MongoDB can&#8217;t use multiple indexes together like MySQL and other RDBMS can (see &#8220;<a href="http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html">Index Merge Optimization</a>&#8220;). This means that if a query is selecting or sorting based on multiple fields, a compound index should be created with those fields for the query to run most efficiently.</p>
<h3>MongoDB is for high-memory and 64-bit systems only</h3>
<p>Although MongoDB can be downloaded, compiled, and installed on 32-bit systems, it should never be run in production on them. This is because <a href="http://www.mongodb.org/display/DOCS/Indexing+Advice+and+FAQ#IndexingAdviceandFAQ-MakesureyourindexescanfitinRAM.">MongoDB stores all indexes in memory</a> as well as <a href="http://www.mongodb.org/display/DOCS/Caching">memory-mapped files</a> for all disk I/O for increased speed and throughput. While these two facts aren&#8217;t &#8220;gotchas&#8221; themselves &#8211; they are clearly explained on the website &#8211; it does mean that MongoDB can quickly use a lot of memory, especially as the size of your database grows and becomes significant. Since 32-bit systems have an effective <a href="http://en.wikipedia.org/wiki/3_GB_barrier">3GB memory limit</a> of addressable memory space, they prevent you from being able to add more memory as the size of your database grows. This is also something to think about if you plan to run MongoDB on a small VPS with limited memory, even if it is 64-bit. You may be forced into a memory upgrade sooner than you are prepared for if your database is large or rapidly growing.</p>
<h3>Subtle Differences</h3>
<p>When starting out with MongoDB, it&#8217;s easy to draw a lot of parallels to MySQL and make a lot of assumptions based on those similarities. Collections are kind of like tables, fields are kind of like columns, a document is kind of like a row. You may find yourself going on to make more assumptions about how it&#8217;s storing data, how you can query it, what you can do with it, etc. without even knowing it. So while MongoDB has a lot of similar features and is one of the easiest NoSQL databases to transition to from a relational database, it has some very distinct differences &#8220;under the hood&#8221; that you have to be aware of and plan for ahead of time. The <a href="http://www.mongodb.org/display/DOCS/Manual">MongoDB documentation</a> is well-written, and is pretty good at explaining any potential differences or &#8220;gotchas&#8221;, so make sure to read it thoroughly before making the jump &#8211; and watch that first step.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/mongodb-gotchas/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>NoSQL First Impressions: Object Databases Missed the Boat</title>
		<link>http://www.vancelucas.com/blog/nosql-first-impressions-object-databases-missed-the-boat/</link>
		<comments>http://www.vancelucas.com/blog/nosql-first-impressions-object-databases-missed-the-boat/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 17:00:57 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[rdbms oodb]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=551</guid>
		<description><![CDATA[I&#8217;ve spent the past few weeks here at work researching and playing with NoSQL databases (and especially MongoDB) for a new feature we&#8217;re developing that doesn&#8217;t easily fit into a relational model. And so far, I really like what I see. The profoundness of the shift away from the relational model and the implications that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the past few weeks here at work researching and playing with <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL</a> databases (and especially <a href="http://mongodb.org">MongoDB</a>) for a new feature we&#8217;re developing that doesn&#8217;t easily fit into a relational model. And so far, I <em>really</em> like what I see. The profoundness of the shift away from the relational model and the implications that has just blow my mind. <strong>You no longer have to fragment your data to persist it</strong><em>.</em> You just store it. That&#8217;s it. No more hours toiling over the design your table schema and how to break apart the data you put together just to fit it into a relational model. You can now store your data exactly how you use it in your application, with no other special needs or <a href="http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch">impedance mismatches</a>. Going back to an <a href="http://en.wikipedia.org/wiki/RDBMS">RDBMS</a> system now just seems illogical &#8211; it&#8217;s like breaking apart a camera tripod just to fit it in the same standard size case you&#8217;ve been using for years instead of just collapsing it and finding a different case that fits it better. All that effort you go though tearing down your tripod and putting it back together every time you use it is wasted and unnecessary. It&#8217;s a symptom of the larger problem that your case doesn&#8217;t fit your tripod.<span id="more-551"></span></p>
<p>Once you fully get the NoSQL viewpoint and the implications it has on  the future of data storage, you have one of those &#8220;why didn&#8217;t anyone  think of this sooner?&#8221; moments. And yes, I know key/value stores like <a href="http://memcached.org/">memcached</a> existed long before this whole new &#8220;NoSQL&#8221; movement, but it&#8217;s not quite  the same thing.</p>
<h3>Object Databases</h3>
<p>Object databases are an interesting case. They are in the &#8220;NoSQL&#8221; category and solve the same problem other NoSQL databases do &#8211; creating a storage mechanism that fits your data instead of making your data fit a predefined rigid storage mechanism. So why didn&#8217;t they catch on? What gives? It&#8217;s anyone&#8217;s guess why object databases didn&#8217;t catch on and achieve widespread adoption, but one thing is for sure &#8211; <strong>object databases really missed the boat</strong> while other NoSQL database technologies are running rings around them.</p>
<p>The primary problem is that most object databases are designed for a specific language, like Java or .NET. Some have more language support than others, but the problem is still the same &#8211; by integrating in directly with a language&#8217;s object model they depend on specific language implementations, which severely limits adoption. They solve the impedance mismatch problem that RDBMSes present, but <strong>fail to provide language-agnostic data persistence and access</strong>, effectively tying their use to specific technology stacks and platforms.</p>
<h3>The Best of Both Worlds</h3>
<p>NoSQL databases are gaining traction like no other database technology has in over 30 years. The reason is that <strong>good NoSQL databases solve both key data storage problems: impedance mismatches AND language-agnosticism.</strong> By storing the data in an intermediary format like JSON (or BSON) and allowing custom file content types, the focus is on the actual data itself instead of specific technologies or data models. The technology stack becomes irrelevant, and the walls to gaining user adoption crumble.</p>
<p>The bottom line is that NoSQL databases are not just the latest fad. They represent a fundamental paradigm shift in data storage and are an entirely new way of thinking about how to store and access your data in a way that makes sense for your actual usage. NoSQL databases are absolutely something you should be paying attention to and following closely &#8211; they are a strong contender to the RDBMS model and will likely become the de-facto data storage choice for most new web applications within a decade.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/nosql-first-impressions-object-databases-missed-the-boat/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

