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_nam开发者_运维百科e)
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!
Learn all three.
- 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.
- 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
- At some stage you can not use the
- 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.
精彩评论