I have a collection in mongodb:
> use my_db
switched to db my_db
> db.my_coll.count()
278
I have a class in ruby:
class MyColl
include MongoMapper::Document
key :fst, Integer
key :sec, Float
end
When I call:
MongoMapper.database = 'my_db'
MyColl.count
#=> 0
though I definitely expected to receive the same result as in mongo console. No errors, no nothing.
What am I missing here?
MongoMapper'sActiveRecordconvention expects class name to correspond collection name as:That said, class
MyCollexpects the underlying collection to be namedmy_colls. Despite that there is no such collection in the database,MongoMappersilently assumes the user wants to create this collection transparently. That's whyMyColl.countreturns zero, rather than throws an exception.will do the trick.