Created
October 16, 2013 13:34
-
-
Save dmgarland/7007800 to your computer and use it in GitHub Desktop.
Mongo CRUD
This file contains hidden or 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 'mongo' | |
| # Get a connection to Mongo | |
| db = Mongo::Connection.new | |
| # Insert records (Create) | |
| db["movies_db"]["movies"].insert({ hello: "there"}) | |
| # Find records (Read) | |
| db["movies_db"]["movies"].find_one | |
| db["movies_db"]["movies"].find(:title => params[:name]) | |
| # Update records (Update) | |
| find_criteria = { :hello => "there" } | |
| values = { :hello => "matey" } | |
| db["movies_db"]["movies"].update(find_criteria, values) | |
| # Delete (Delete) | |
| db["movies_db"]["movies"].remove(:hello => "matey") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment