No idea why this is not working. It’s the first time I am working with Mongo, but from all the docs I have read, this should work? Anyone have any idea what I am missing?
require 'rubygems'
require 'sinatra/base'
require 'mongo_mapper'
mongo_server = '127.0.0.1'
mongo_database = 'inone'
MongoMapper.connection = Mongo::Connection.new(mongo_server)
MongoMapper.database = mongo_database
# DB model
class URLstore
include MongoMapper::Document
key :url_key, String
key :url, String
end
class URLnip < Sinatra::Base
get '/testmongo' do
nipurl = URLstore.new(:url_key => "abc", :url => "www.google.com")
nipurl.save
end
end
Opening the Mongo terminal I can see the DB get’s created
> show dbs
inone 0.203125GB
but doing this brings back no results at all
> db.inone.find()
>
or
> db.inone.find({url : 'www.google.com'})
>
same thing nothing.
Shouldn’t that be
db.urlstore.find()? Or howeverMongoMapperchanges the case. What doesshow collectionsin a Mongo shell say after you select the right database?