Skip to content

Instantly share code, notes, and snippets.

@jhancock
Created September 2, 2009 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhancock/179900 to your computer and use it in GitHub Desktop.
Save jhancock/179900 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'mongo'
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo::Connection.new(host, port).db('jon')
coll = db.collection('test')
puts ">> clear collection jon:test"
coll.clear
puts "Count of jon:test #{coll.count}"
puts ">> insert an object with attribute sample1"
string = "hello"
puts string
puts string.encoding
oid = coll.save({'sample1' => string})
doc = coll.find_one()
puts doc['sample1'].encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment