views:

83

answers:

1

Im using MongoDB and Ruby.

I have noticed there are different DSL:s.

The Javascript DSL used with the MongoDB client (mongo):

show dbs
use my_db
db.person.find({first_name: "Syd"})

The Ruby DSL used with the Ruby driver for MongoDB:

connection = Mongo::Connection.new
connection.database_names.each { |name| puts name }
connection.database_info.each { |info| puts info.inspect}
person.find({"hello" => "world"})

Then the MongoID/MongoMapper DSL for MongoDB:

Person.desc(:last_name).asc(:first_name)
Person.descending(:last_name).ascending(:first_name)
Person.all(:conditions => { :first_name => "Syd" })

Questions:

  • Is it correct MongoID/MongoMapper is build on top of the Ruby DSL that is built on top of MongoDB client's DSL?

  • Should I learn all three DSL:s or just make my pick depending on the level of abstraction I want?

  • Are there any reasons I would like to learn/use the MongoDB client DSL? Can I use it in a script or is it just interactive with it's client (mongo)?

Thanks!

+1  A: 

Learn all three.

  1. The first one is going to be heavily used when you want to test query or find data etc, especially when you are in production. You would want to use the mongo client to do this kind of stuff.
  2. The second one is used when the driver DSL does not support the features on the mongo. e.g:
    • At some stage you can not use the $or operator with MongoMapper when it was already supported on mongo 1.5
    • The last time I used mongoid and mongomapper does not support mapping to GridFS so you would use the driver API for this
    • And the last time I used, mongoid and mongomapper does not support map-reduce again you have to use the driver API for this situation
  3. MongoMapper and Mongoid is used to map your domain object to mongo document, at some stage where the ODM is lack of you have to have the fallback plan, which is to use the mongo driver API.

Hope that helps.

jpartogi
Could I use the mongo client commands from inside ruby? I know there is the ruby dsl, but I was thinking about something similar to running a SQL query from within PHP. Could you run the mongo client commands/queries from ruby?
never_had_a_name
You can, but why would you want to do that? It's more natural to use the Ruby syntax.
jpartogi
I know, just out of curiosity. How do I do it?
never_had_a_name