Skip to content

Instantly share code, notes, and snippets.

@kiyukuta
Created August 25, 2012 16:56
Show Gist options
  • Save kiyukuta/3467876 to your computer and use it in GitHub Desktop.
Save kiyukuta/3467876 to your computer and use it in GitHub Desktop.
Mongoid sample, for sinatra app.
./mongoimport -d mongoid_test -c tmps --type csv --file testlist.csv --headerline
require 'sinatra'
require 'mongoid'
require 'json'
require 'sinatra/reloader' if development?
Mongoid.load!("mongoid.yml", :development)
class Tmp
include Mongoid::Document
field :name, type: String
field :num, type: Integer
field :val, type: Integer
end
get '/test.json' do
content_type :json
allTmp = Tmp.all
allTmp.to_json
end
get '/' do
"Hello world, %d"%Tmp.count
end
require 'sinatra'
require './app'
run Sinatra::Application
development:
sessions:
default:
database: mongoid_test
hosts:
- localhost:27017
name num val
one 1 10
two 2 20
three 3 30
four 4 40
aiii 5 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment