mongo-ruby-driver/tests/mongo-qa/find1

16 lines
538 B
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
if __FILE__ == $0
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'] }