2008-11-22 01:00:51 +00:00
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
require 'mongo'
|
|
|
|
|
|
|
|
include XGen::Mongo::Driver
|
|
|
|
|
2008-12-04 22:04:06 +00:00
|
|
|
host = ARGV[0] || 'localhost'
|
|
|
|
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
|
|
|
|
|
|
|
puts "Connecting to #{host}:#{port}"
|
2008-12-05 00:07:49 +00:00
|
|
|
db = Mongo.new(host, port).db('ruby-mongo-examples-simple')
|
2008-11-22 01:00:51 +00:00
|
|
|
coll = db.collection('test')
|
|
|
|
coll.clear
|
|
|
|
|
|
|
|
doc = {'a' => 1}
|
|
|
|
coll.insert(doc)
|
|
|
|
|
|
|
|
doc = {'a' => 2}
|
|
|
|
coll.insert(doc)
|
|
|
|
|
2008-12-02 00:36:20 +00:00
|
|
|
doc = {'a' => 3}
|
|
|
|
coll.insert(doc)
|
|
|
|
|
2008-12-02 01:01:13 +00:00
|
|
|
puts "There are #{coll.count()} records in the test collection. Here they are:"
|
2008-11-22 01:00:51 +00:00
|
|
|
coll.find().each { |doc| puts doc.inspect }
|