Skip to content

Instantly share code, notes, and snippets.

@dmgarland
Created October 16, 2013 13:34
Show Gist options
  • Select an option

  • Save dmgarland/7007800 to your computer and use it in GitHub Desktop.

Select an option

Save dmgarland/7007800 to your computer and use it in GitHub Desktop.
Mongo CRUD
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