Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created December 5, 2013 20:39
Show Gist options
  • Save yanmhlv/7813469 to your computer and use it in GitHub Desktop.
Save yanmhlv/7813469 to your computer and use it in GitHub Desktop.
ruby and mongo
require 'Mongo'
include mongo
conn = MongoClient.new('192.168.1.103')
db = conn['test_database']
coll = db['test_collection']
coll.find.each do |x|
puts x['_id'].generation_time
end
puts conn.database_names
puts db.collection_names
auth = db.authenticate(username, password)
coll.insert({:name => 'MongoDB', :type => 'database', :count => 1, :info => {:x => 1, :y => 2}})
puts coll.find_one
coll.find.each {|row| puts row.inspect }
coll.find.to_a
coll.find_one({:i => {'$gt' => 50}}, :fields => [:name, :type])
coll.index_information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment