Category Archive: Database

Apr 06

RSpec, Mongo and Database Cleaner

This is kinda obvious, once you see it… But I’d figure it might help someone, someday. I wanted to create a document one time, so I put it in the before :all block. Yet, in the “it should” block, the document was gone, spec failed. If I changed to a before :each block, the spec …

Continue reading »

Feb 19

Anatomy of a MongoDB Profiling Session

This particular application has been collecting data for months now, but hasn’t really had any users by design. At 33GB of data, pulling up a list of messages received was taking f-o-r-e-v-e-r! So I decided to document how to go about and fix a running production system… Hope it helps. Log into mongo console and …

Continue reading »

Feb 07

Exporting MongoMapper Objects to JSON

I wanted to export a MongoMapper document and it’s related documents as JSON — with embedded arrays for the collections. Invoking to_json did not seem to work perfectly, so I set about to discover what was going on. Conclusion If you use Embedded Documents for every associated document, the to_json method will work perfectly. If …

Continue reading »

Dec 30

Uncle Bob Challenges The Architecture of a Rails App

Uncle Bob has a very interesting keynote at the Ruby Midwest 2011 conference. I developed apps with the fundamental architecture of the following (with dependencies only crossing one layer): —— UI Layer —— Business Object Layer —— Data Mgt. Layer —— Born from the one pattern that is king of the hill in my book: …

Continue reading »

Dec 28

MongoDB Group Map-Reduce Performance

I wanted to get some aggregated count data by message type for a collection with over 1,000,000 documents. The model is more or less this (a lot removed for simplicity): class MessageLog include MongoMapper::Document # Attributes :::::::::::::::::::::::::::::::::::::::::::::::::::::: # Message’s internal timestamp / when it was sent key :time, Time # Message type key :event_type, String, …

Continue reading »

Dec 01

MongoDB Index Performance

The effect of adding indexes on query performance

As part of this (unintended) mini-series on MongoDB and indexing, I had written a little test to see if I could document performance gains through indexing. I used realworld data, albeit only 50,000 records, to query out a handful or documents (24 being the most). Related posts: Indexing Discussed Configuring MongoDB Indexes Here is the …

Continue reading »

Nov 26

A Walk Through the Valley of Indexing in MongoDB

As you walk through the valley of MongoDB performance, you will undoubtedly find yourself wanting to optimize your indexes at some point or other. How to Watch Your Queries Run your database with profiling on. I have an alias for starting up mongo in profile mode (‘p’ stands for profile): alias mongop=”<mongodb-install>/bin/mongod –smallfiles –noprealloc –profile=1 …

Continue reading »

Nov 25

Configuring MongoMapper Indexes in Rails App

Ever wonder where the best place is to specify indexes for MongoMapper classes? Me too… Here I provide three styles that I have progressed through.

Sep 13

Development with MongoMapper

A question popped up: Mongo is schema-less, that means we can create new fields when needed, I read the mongo mapper document, it still needs to write model code like below, so we have to change the code below when we need new field, is this kind of limitation to use the schema-less database mongodb? …

Continue reading »

Jun 15

Baby Steps with Map-Reduce

I figured I would add some pages to serve as my own reference docs for stuff I wrestle to the ground. I have been putting these sorts of things on internal project wikis for eons (even before wikis!). But that doesn’t do anybody any good. Here is a place to read about Map-Reduce (Part 1). …

Continue reading »

Older posts «