Created
August 25, 2012 16:56
-
-
Save kiyukuta/3467876 to your computer and use it in GitHub Desktop.
Mongoid sample, for sinatra app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./mongoimport -d mongoid_test -c tmps --type csv --file testlist.csv --headerline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require './app' | |
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
sessions: | |
default: | |
database: mongoid_test | |
hosts: | |
- localhost:27017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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