I have to read an existing mongo database. Is mongoid suitable for this?
All the tutorials I found were about building a mongo database from scratch.
I have tried accessing the database using mongoid, and have no luck displaying existing information, this is what I tried.
mongoid.yml:
development:
host: localhost
database: managementdb
test:
host: localhost
database: managementdb
I did a scaffold (I don’t like how mongoid takes over scaffolding)
the model:
class GamerProfile
include Mongoid::Document
store_in :profile
field :facebookId, :type => String
field :playerName, :type => String
field :locale, :type => String
field :dateJoined, :type => Time
end
But the existing information in localhost:27017/managementdb/Profile isn’t displaying in the view.
I only need readonly access. Would mongomapper or mongomodel be more suited?
I’ve tried mongomapper after having tried mongoid, and it does exactly what it’s name implies.
Let say I have a collection called
Userin mongodb which relates to a user in a game but doesn’t necessarily relate to theUsermodel for that application then I useset_collection_name "User"in a model calledGameUserfor example.My initialiser is lifted straight from the mongodb docs; which use mongomapper for their example.
And my model looks like this:
And now my scaffold loads to data from the
GameUserperfectly.