mongo-ruby-driver/test/mongo-qa/find1
2009-08-18 10:07:01 -04:00

16 lines
530 B
Ruby

#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
if $DEBUG
db.drop_collection('c')
c = db.collection('c')
(5..15).each { |i| c.insert(:x => 0, :y => i, :z => (i+64).chr) }
(1..50).each { |i| c.insert(:x => 1, :y => i, :z => (i+64).chr) }
(5..15).each { |i| c.insert(:x => 2, :y => i, :z => (i+64).chr) }
end
cursor = db.collection('c').find({'x' => 1}, :sort => 'y', :offset => 20, :limit => 10)
cursor.each { |row| puts row['z'] }