Ok, so some background. I’m curious as to this post at lunarlogicpolska.com which shows mysql and mongodb living together in harmony. Some data is in mysql (nice and structured), some data is in a crazy-fast document database. It doesn’t matter. Datamapper combines many sources into a common abstraction layer that your models can pick and choose which to use. At least that’s the dream. I was going to play around with this but hit a bit of a snag.
First the post at lunarlogicpolska.com basically boils down to this bit:
Unfortunately, this wouldn’t run on my box. I had installed my gems like so: gem install dm-mongo-adapter --pre
and got a big ol problem while install rdoc (weird):
RDoc::Parser::Ruby failure around line 220 of
lib/dm-core/query/conditions/operation.rb
[snip]
The internal error was:
(RDoc::Error) Name or symbol expected (got #<RDoc::RubyToken::TkAMPER:0x00000005509380>)
ERROR: While generating documentation for dm-core-0.10.2
... MESSAGE: Name or symbol expected (got #<RDoc::RubyToken::TkAMPER:0x00000005509380>)
Doing the same gem install command got rid of the rdoc error. Ok, no problem. This is a prototype I’m trying to build, no sweat if rdoc installation is a bit flaky. Unfortunately, I didn’t get much farther than this with the actual code until I changed lunarlogicpolska’s example to this:
I found this out by playing around with irb. The order matters:
You can see here that I required dm-core first but then it doesn’t know what dm-mongo-adapter or mongo_adapter is. Quit irb and try it a different way:
Works great. I have a DataMapper::Mongo::Adapter object. Unfortunately, I didn’t get any farther than this because the current prerelease isn’t compatible with mongo 1.6. It just complains about :slave_ok needs to be set to true. Even though I’m connecting to the master node of my replica set.
Mongo::ConfigurationError: Trying to connect directly to slave; if this is what
you want, specify :slave_ok => true.
So even though this isn’t a complete fix, when the new drop of dm-mongo-adapter hits, this little test will be useful. And then I can figure out if datamapper is as awesome as I think it is.