I try to use datamapper and mongoid on my project. I followed the link https://github.com/solnic/dm-mongo-adapter. But there is no so much information. I assimilate to datamapper and sqlite3 adapter in this post: http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-working-with-datamapper/ Everything is ok with sqlite3, but i bogged down with mongodb.
When I run "ruby rm.db" in console i take "dm.rb:1:in `': uninitialized constant DataMapper (NameError)" error.
How can i resolve this problem? I added these gems in my gemfile below:
dm-core
dm-aggregates
dm-migrations
mongo
mongodb
mongo_ext
Then I added below code in a file named dm.rb in the root of project.
DataMapper.setup(:default,
:adapter => 'mongo',
:database => 'my_mongo_db',
)
# Define resources
class Student
include DataMapper::Mongo::Resource
property :id, ObjectId
property :name, String
property :age, Integer
end
class Course
include DataMapper::Mongo::Resource
property :id, ObjectId
property :name, String
end
# No need to (auto_)migrate!
biology = Course.create(:name => "Biology")
english = Course.create(:name => "English")
# Queries
Student.all(:age.gte => 20, :name => /oh/, :limit => 20, :order => [:age.asc])
# Array and Hash as a property
class Zoo
include DataMapper::Mongo::Resource
property :id, ObjectId
property :opening_hours, Hash
property :animals, Array
end
Zoo.create(
:opening_hours => { :weekend => '9am-8pm', :weekdays => '11am-8pm' },
:animals => [ "Marty", "Alex", "Gloria" ])
Zoo.all(:animals => 'Alex')