Print

Print


On 5/13/10 8:59 AM, Fernando Gómez wrote:
> Any suggestions? Do other document oriented databases offer a better
> solution for this?
>    
Hey Fernando,

I'd suggest you checkout CouchDB. CouchDB uses JSON as it's document 
format, provides advanced indexing (anywhere in the JSON docs) via 
map/reduce queries that are typically written in JavaScript. The 
map/reduce queries are simple lamda JavaScript functions that are part 
of a "design" document (also a simple JSON object) in CouchDB. Check out 
the following two links for more info:
http://books.couchdb.org/relax/design-documents/design-documents
http://books.couchdb.org/relax/design-documents/views

A simple map reduce query using your city and address.city keys would 
look something like this:

function (doc) {
   if (doc.city) {
     emit(doc.city, doc);
   } else if (doc.address.city) {
     emit(doc.address.city, doc);
   }
}

That function would return the full document representation "keyed" by 
their cities (which is handy for sorting and later reducing by counting 
unique cities).

CouchDB lets you focus on pulling out the data you want, and it handles 
the indexing. Pretty handy. :)

Let me know if you have other questions about CouchDB.

Take care,
Benjamin