<?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>Nerdpress.org &#187; mongodb</title>
	<atom:link href="http://www.nerdpress.org/tag/mongodb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nerdpress.org</link>
	<description>^__^</description>
	<lastBuildDate>Thu, 03 May 2012 15:03:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Silex and MongoDB simply</title>
		<link>http://www.nerdpress.org/2012/01/30/silex-and-mongodb-simply/</link>
		<comments>http://www.nerdpress.org/2012/01/30/silex-and-mongodb-simply/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 14:27:34 +0000</pubDate>
		<dc:creator>Ivo Bathke</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[silex]]></category>

		<guid isPermaLink="false">http://nerdpress.org/?p=2033</guid>
		<description><![CDATA[Using MongoDB in your Silex Project is quite easy. I will show this with my Superleansilexplate and will integrate it there as an example. Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional gist. Given you have some smaller amount of data like a counter that needs to be [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Using MongoDB in your Silex Project is quite easy.</p>
<p>I will show this with my <a href="https://github.com/ivoba/superleansilexplate">Superleansilexplate</a> and will integrate it there as an example.<br />
Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional <a href="https://gist.github.com/1704512">gist</a>.</p>
<p>Given you have some smaller amount of data like a counter that needs to be stored or other loose coupled datasets, we simply speak to MongoDB &#8220;directly&#8221; and store the data via <a href="https://github.com/doctrine/mongodb">Doctrine MongoDB Abstraction Layer</a>.<br />
Since i presume the Data / Document Structure isnt that complex we dont use <a href="https://github.com/doctrine/mongodb-odm">Doctrine MongoDB ODM</a> (the Object Document Mapper).<br />
If you want to use it instead, try this <a href="https://github.com/docteurklein/SilexExtensions">Silex Extensions</a>.</p>
<p><span id="more-2033"></span></p>
<p>So we use this <a href="https://github.com/fate/Silex-Extensions">SilexExtensions</a> collection and install it via git:</p>
<pre class="brush: bash; title: ; notranslate">
 cd mysilexproject
 git clone git@github.com:fate/Silex-Extensions.git vendor/silex-extension
</pre>
<p>Then we install the doctrine mongodb libary manually:</p>
<pre class="brush: bash; title: ; notranslate">
 git clone --recursive https://github.com/doctrine/mongodb vendor/mongodb
</pre>
<p>The extension collection has some more poviders but you can just ignore them and just focus on the MongoDbExtension.</p>
<p>-<em> i actually dont like extensions collections. i would prefer to clone each extensions individually. thou its not much code overhead, but when it comes to the vendor dependencies it can become quite messy IMHO</em> -</p>
<p>Alright now the code.<br />
Edit src/app.php and register the namespace for the extension:</p>
<pre class="brush: php; title: ; notranslate">
 $app['autoloader']-&gt;registerNamespace('SilexExtension', __DIR__ . '/../vendor/silex-extension/src');
</pre>
<p>Then register the MongoDbExtension;</p>
<pre class="brush: php; title: ; notranslate">
 $app-&gt;register(new SilexExtension\MongoDbExtension(), array(
 'mongodb.class_path' =&gt; __DIR__ . '/../vendor/mongodb/lib',
 'mongodb.connection' =&gt; array(
 'server' =&gt; 'mongodb://mysecretuser:mysecretpassw@localhost',
 'options' =&gt; array(),
 'eventmanager' =&gt; function($eventmanager) {
 }
 )
 ));
</pre>
<p>and finally query your MongoDB collection of choice and display the resultset as json:</p>
<pre class="brush: php; title: ; notranslate">
$app-&gt;get('/data-from-mongodb', function() use($app) {

$coll = $app['mongodb']-&gt;selectDatabase('mydb')-&gt;selectCollection('mycoll');
 $query = array(
 'query' =&gt; 'value'
 );
 $sort = array(
 'count' =&gt; -1,
 );
 $r = $coll-&gt;find($query)-&gt;sort($sort)-&gt;toArray();
 $response = new Response();
 $response-&gt;headers-&gt;set('Content-type', 'application/json');
 $response-&gt;setContent(json_encode($r));
 return $response;
 });
</pre>
<p>Easy</p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.nerdpress.org/2012/01/30/silex-and-mongodb-simply/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Migrate to Mongolab</title>
		<link>http://www.nerdpress.org/2011/09/26/migrate-to-mongolab/</link>
		<comments>http://www.nerdpress.org/2011/09/26/migrate-to-mongolab/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 05:38:07 +0000</pubDate>
		<dc:creator>Ivo Bathke</dc:creator>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[vServer]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://nerdpress.org/?p=1738</guid>
		<description><![CDATA[Recently i ran into RAM troubles on my vserver for some reasons, i encountered the evil: So first i suspected mongodb to use up loads of memory as top showed. But after some recherche work i learned mongodb only -seems- to use a lot of memory. see here and here and here The actual usage [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Recently i ran into RAM troubles on my vserver for some reasons, i encountered the evil:</p>
<pre class="brush: bash; title: ; notranslate">
Cannot allocate memory at ...
</pre>
<p>So first i suspected <a href="http://www.mongodb.org/">mongodb</a> to use up loads of memory as top showed.</p>
<p>But after some recherche work i learned mongodb only -seems- to use a lot of memory.<br />
see <a href="http://blog.mongodb.org/post/101911655/mongo-db-memory-usage">here</a> and <a href="http://www.mongodb.org/display/DOCS/Checking+Server+Memory+Usage">here</a> and <a href="http://stackoverflow.com/questions/4918443/is-it-ideal-that-mongodb-is-using-150-mb-memory/4918676#4918676">here</a><br />
The actual usage was around 20mb RAM, so mongodb was innocent.</p>
<p>The true RAM monsters were some apache and php-fpm zombies, but thats another story.</p>
<p>While suspecting mongodb i thought about outsourcing the mongodb and i found a free and sufficient offer in <a href="https://mongolab.com">mongolab</a>.<br />
My interests were on and i gave it a try.<br />
The free version has a limit for up to 240MB storage and since my app is just a small counter it should last for some time.<br />
<span id="more-1738"></span></p>
<p>The registration was easy, creation of the database aswell and the administration panel is also pretty cool and informative.<br />
<img class="alignnone size-medium wp-image-1743" style="border-style: initial; border-color: initial;" src="http://nerdpress.org/wp-content/uploads/2011/09/mongolab-300x167.png" alt="Mongolab-300x167 in " width="300" height="167" /><br />
Then create a user and migrate:</p>
<p>First get my data from the vserver on the vserver:</p>
<pre class="brush: bash; title: ; notranslate">
 mongodump --host 127.0.0.1
</pre>
<p>Then fetch it to my local machine:</p>
<pre class="brush: bash; title: ; notranslate">
 scp -r me@vserver.de:/var/www/vhosts/verrueckte/dump/mongodumpdata .
</pre>
<p>Ups i didnt had no mongo client on my local machine, go get it:</p>
<pre class="brush: bash; title: ; notranslate">
 sudo apt-get install mongodb-clients
</pre>
<p>Now connect to the mongolab via your console</p>
<pre class="brush: bash; title: ; notranslate">
 mongo db123xyz.mongolab.com:12345/thedb -u &lt;user&gt; -p &lt;pw&gt;
</pre>
<p>Hey works, great!<br />
Alright see you later.</p>
<pre class="brush: bash; title: ; notranslate">
 &gt; exit;
</pre>
<p>Now import the dumps to continue the counter there were i stopped.</p>
<pre class="brush: bash; title: ; notranslate">
 cd mongodumpdata
 mongorestore -h db123xyz.mongolab.com:12345 -d thedb -u -p .
</pre>
<p>Good!</p>
<p>Then teach the php app the new connection:</p>
<pre class="brush: php; title: ; notranslate">
 $this-&gt;host = 'mongodb://user:pw@db123xyz.mongolab.com:12345/thedb';
 new mongo($this-&gt;host);
</pre>
<p>There you go! The counter is storing its stuff to the mongolab database.<br />
And i can stop the mongod on my machine and free some memory.</p>
<pre class="brush: bash; title: ; notranslate">
 ps aux | grep mongodb
 kill &lt;PID&gt;
</pre>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.nerdpress.org/2011/09/26/migrate-to-mongolab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grouping &amp; Sorting in MongoDB</title>
		<link>http://www.nerdpress.org/2010/07/24/grouping-sorting-in-mongodb/</link>
		<comments>http://www.nerdpress.org/2010/07/24/grouping-sorting-in-mongodb/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 10:45:21 +0000</pubDate>
		<dc:creator>Ivo Bathke</dc:creator>
				<category><![CDATA[DB]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nerdpress.org/?p=1073</guid>
		<description><![CDATA[Will man mit PHP und MongoDB soetwas wie &#8220;SQL Aggregate Functions&#8221; umsetzen muss man sich etwas verbiegen. MongoDb hat zwar eine group() function, die in etwa SQLs GROUP BY entspricht, allerdings kann man dies nicht kombinieren mit SORT oder LIMIT bzw den sort() und limit() Funktionen, da diese keinen Cursor zurückgibt sondern direkt ein Array. [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Will man mit PHP und MongoDB soetwas wie &#8220;<strong>SQL Aggregate Functions</strong>&#8221; umsetzen muss man sich etwas verbiegen.</p>
<p>MongoDb hat zwar eine <a href="http://www.php.net/manual/de/mongocollection.group.php">group()</a> function, die in etwa SQLs <em>GROUP BY</em> entspricht, allerdings kann man dies nicht kombinieren mit <em>SORT</em> oder <em>LIMIT</em> bzw den <a href="http://www.php.net/manual/de/mongocursor.sort.php">sort()</a> und <a href="http://www.php.net/manual/de/mongocursor.limit.php">limit()</a> Funktionen, da diese keinen Cursor zurückgibt sondern direkt ein Array.</p>
<p>Will man also sortieren und limitieren muss man sich des Map / Reduce features von MongoDB bedienen.</p>
<p><span id="more-1073"></span></p>
<p>Ein Query wie folgt:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT referer.URL, count(*) AS cnt
FROM `referer`
GROUP BY referer.URL
ORDER BY cnt ASC LIMIT 25
</pre>
<p>&#8230;wird dann über <a href="http://www.php.net/manual/de/mongodb.command.php">Command()</a> so umgesetzt:</p>
<pre class="brush: php; title: ; notranslate">
$map = new MongoCode(&quot;function() { emit(this.url,1); }&quot;);
$reduce = new MongoCode(&quot;function(k, vals) { &quot;.
			&quot;var sum = 0;&quot;.
			&quot;for (var i in vals) {&quot;.
			&quot;sum += vals[i];&quot;.
			&quot;}&quot;.
			&quot;return sum; }&quot;);
$r = $this-&gt;db_handler-&gt;command(array(
		    	&quot;mapreduce&quot; =&gt; &quot;referer&quot;,
		    	&quot;map&quot; =&gt; $map,
		    	&quot;reduce&quot; =&gt; $reduce));
$r = $this-&gt;db_handler-&gt;selectCollection($r['result'])-&gt;find();
$r-&gt;sort(array('value' =&gt; -1));
$r-&gt;limit(25);
$data = array();
foreach ($r as $ref) {
	$data[$ref['_id']] = $ref['value'];
}
return $data;
</pre>
<p>In die Reduce Funktion kann man sämtliche Abfrage-Logik packen, was es zu einem ziemlich mächtigem Konstrukt macht.<br />
Hat man sich einmal dran gewöhnt, lässt sich eine Menge damit anstellen. </p>
<p>Danke auch an diesen <a href="http://kylebanker.com/blog/2009/12/mongodb-map-reduce-basics/">Blog</a>.</p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.nerdpress.org/2010/07/24/grouping-sorting-in-mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datei-Endungen im Vork Framework</title>
		<link>http://www.nerdpress.org/2010/06/10/vork-framework-change-filetype-dateityp/</link>
		<comments>http://www.nerdpress.org/2010/06/10/vork-framework-change-filetype-dateityp/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 07:36:13 +0000</pubDate>
		<dc:creator>Max Girkens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[vork]]></category>

		<guid isPermaLink="false">http://nerdpress.org/?p=1028</guid>
		<description><![CDATA[Von Haus aus kommen im Vork Framework alle MVC Dateien ohne Endung daher. Wer das ändern möchte kann folgende Dinge tun: in der Klasse config in der Datei .config folgendes einfügen: dann erwartet vork im MVC Ordner Dateien mit der Endung .php. Um alle Dateien umzubenennen braucht man eigentlich nur Windows Vista, eine präzise Maus [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Von Haus aus kommen im <a href="http://vork.us">Vork Framework</a> alle MVC Dateien ohne Endung daher.<br />
Wer das ändern möchte kann folgende Dinge tun:</p>
<p>in der Klasse config in der Datei .config folgendes einfügen:</p>
<pre class="brush: php; title: ; notranslate">
public $fileExtension = '.php';
</pre>
<p>dann erwartet vork im MVC Ordner Dateien mit der Endung .php.<br />
Um alle Dateien umzubenennen braucht man eigentlich nur Windows Vista, eine präzise Maus und etwas Geduld.<br />
oder folgende Zeile:</p>
<pre class="brush: bash; title: ; notranslate">
find /myVorkFolder/mvc -type f -exec mv '{}' '{}'.php ;
</pre>
<p><span id="more-1028"></span><br />
Vork ist auf jeden Fall schnell und hat direkt einen Wrapper für PHP-MongoDB mit an Bord.<br />
Wie man Vork auschliesslich mit Mongo nutzen kann steht <a href="http://vork.us/install#otherdatabases">hier</a>:</p>
<pre class="brush: php; title: ; notranslate">
If you are exclusively using MongoDB as your database (and not using an RDBMS in conjunction) then
uncomment the last line in the dbConnect() method
self::$modelObjects = array('mongo');
and comment out lines
self::$db = new $db(...)
and
self::$modelObjects[] = 'mongo';
as well as the last line in the .config file:
require '.config-rdbms';
</pre>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.nerdpress.org/2010/06/10/vork-framework-change-filetype-dateityp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mongomongomongomongo</title>
		<link>http://www.nerdpress.org/2010/06/04/mongomongomongomongo/</link>
		<comments>http://www.nerdpress.org/2010/06/04/mongomongomongomongo/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 21:27:28 +0000</pubDate>
		<dc:creator>Max Girkens</dc:creator>
				<category><![CDATA[DB]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[spidermonkey]]></category>
		<category><![CDATA[WTFs]]></category>

		<guid isPermaLink="false">http://nerdpress.org/?p=1018</guid>
		<description><![CDATA[Man wird möglicherweise ein bisschen nervös, aber auch schlauer: http://www.parleys.com/#st=5&#038;sl=4&#038;id=1864 Und Doctrine macht auch in Sachen Mongo, hab ich gerade gesehen. http://www.doctrine-project.org/projects/mongodb_odm Wer&#8217;s noch nicht gesehen hat, muss(!) auch mal dieses online shell tutorial auf http://www.mongodb.org anschauen.]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Man wird möglicherweise ein bisschen nervös, aber auch schlauer:<br />
<a href="http://www.parleys.com/#st=5&#038;sl=4&#038;id=1864">http://www.parleys.com/#st=5&#038;sl=4&#038;id=1864</a></p>
<p>Und Doctrine macht auch in Sachen Mongo, hab ich gerade gesehen.<br />
<a href="http://www.doctrine-project.org/projects/mongodb_odm">http://www.doctrine-project.org/projects/mongodb_odm</a><br />
<span id="more-1018"></span></p>
<p>Wer&#8217;s noch nicht gesehen hat, muss(!) auch mal dieses online shell tutorial auf <a href="http://www.mongodb.org">http://www.mongodb.org</a> anschauen. </p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.nerdpress.org/2010/06/04/mongomongomongomongo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

