mongo 0.15.1 → 0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +202 -0
- data/README.rdoc +15 -2
- data/Rakefile +17 -3
- data/bin/autoreconnect.rb +26 -0
- data/bin/fail_if_no_c.rb +11 -0
- data/lib/mongo.rb +9 -2
- data/lib/mongo/admin.rb +1 -1
- data/lib/mongo/collection.rb +86 -25
- data/lib/mongo/connection.rb +11 -0
- data/lib/mongo/constants.rb +15 -0
- data/lib/mongo/cursor.rb +176 -36
- data/lib/mongo/db.rb +84 -97
- data/lib/mongo/errors.rb +7 -1
- data/lib/mongo/types/objectid.rb +5 -0
- data/lib/mongo/util/byte_buffer.rb +12 -0
- data/lib/mongo/util/server_version.rb +69 -0
- data/lib/mongo/{message.rb → util/support.rb} +7 -4
- data/mongo-ruby-driver.gemspec +9 -86
- data/test/test_admin.rb +2 -2
- data/test/test_bson.rb +14 -0
- data/test/test_byte_buffer.rb +14 -0
- data/test/test_chunk.rb +4 -4
- data/test/test_collection.rb +107 -17
- data/test/test_connection.rb +13 -4
- data/test/test_cursor.rb +17 -14
- data/test/test_db.rb +7 -7
- data/test/test_db_api.rb +31 -19
- data/test/test_db_connection.rb +1 -1
- data/test/test_grid_store.rb +8 -8
- data/test/test_helper.rb +25 -0
- data/test/test_objectid.rb +11 -1
- data/test/test_slave_connection.rb +37 -0
- data/test/test_threading.rb +1 -1
- data/test/unit/cursor_test.rb +122 -0
- metadata +26 -46
- data/bin/mongo_console +0 -21
- data/bin/run_test_script +0 -19
- data/bin/standard_benchmark +0 -109
- data/lib/mongo/message/get_more_message.rb +0 -32
- data/lib/mongo/message/insert_message.rb +0 -37
- data/lib/mongo/message/kill_cursors_message.rb +0 -31
- data/lib/mongo/message/message.rb +0 -80
- data/lib/mongo/message/message_header.rb +0 -45
- data/lib/mongo/message/msg_message.rb +0 -29
- data/lib/mongo/message/opcodes.rb +0 -27
- data/lib/mongo/message/query_message.rb +0 -69
- data/lib/mongo/message/remove_message.rb +0 -37
- data/lib/mongo/message/update_message.rb +0 -38
- data/lib/mongo/query.rb +0 -118
- data/test/mongo-qa/admin +0 -26
- data/test/mongo-qa/capped +0 -22
- data/test/mongo-qa/count1 +0 -18
- data/test/mongo-qa/dbs +0 -22
- data/test/mongo-qa/find +0 -10
- data/test/mongo-qa/find1 +0 -15
- data/test/mongo-qa/gridfs_in +0 -16
- data/test/mongo-qa/gridfs_out +0 -17
- data/test/mongo-qa/indices +0 -49
- data/test/mongo-qa/remove +0 -25
- data/test/mongo-qa/stress1 +0 -35
- data/test/mongo-qa/test1 +0 -11
- data/test/mongo-qa/update +0 -18
- data/test/test_message.rb +0 -35
data/test/mongo-qa/admin
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
db.collection('test').insert({'test' => 1})
|
7
|
-
admin = db.admin
|
8
|
-
|
9
|
-
if $DEBUG
|
10
|
-
db.drop_collection('tester')
|
11
|
-
admin.profiling_level = :slow_only
|
12
|
-
end
|
13
|
-
|
14
|
-
['test', 'pdlskwmf', '$'].each { |name|
|
15
|
-
begin
|
16
|
-
admin.validate_collection(name)
|
17
|
-
puts 'true'
|
18
|
-
rescue => ex
|
19
|
-
puts 'false'
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
level_xlation = {:off => 'off', :all => 'all', :slow_only => 'slowOnly'}
|
24
|
-
puts level_xlation[admin.profiling_level]
|
25
|
-
admin.profiling_level = :off
|
26
|
-
puts level_xlation[admin.profiling_level]
|
data/test/mongo-qa/capped
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
if $DEBUG
|
7
|
-
db.drop_collection('capped1')
|
8
|
-
db.drop_collection('capped2')
|
9
|
-
end
|
10
|
-
|
11
|
-
db.create_collection('capped1', :capped => true, :size => 500)
|
12
|
-
coll = db.collection('capped1')
|
13
|
-
coll.insert('x' => 1)
|
14
|
-
coll.insert('x' => 2)
|
15
|
-
|
16
|
-
db.create_collection('capped2', :capped => true, :size => 1000, :max => 11)
|
17
|
-
coll = db.collection('capped2')
|
18
|
-
str = ''
|
19
|
-
100.times {
|
20
|
-
coll.insert('dashes' => str)
|
21
|
-
str << '-'
|
22
|
-
}
|
data/test/mongo-qa/count1
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
if $DEBUG
|
7
|
-
3.times { |i| db.drop_collection("test#{i+1}") }
|
8
|
-
db.create_collection('test1')
|
9
|
-
db.collection('test2').insert({:name => 'a'})
|
10
|
-
c = db.collection('test3')
|
11
|
-
100.times { |i| c.insert(:i => i, :foo => 'bar') }
|
12
|
-
end
|
13
|
-
|
14
|
-
puts db.collection('test1').count
|
15
|
-
puts db.collection('test2').count
|
16
|
-
puts db.collection('test3').find('i' => 'a').count
|
17
|
-
puts db.collection('test3').find('i' => 3).count
|
18
|
-
puts db.collection('test3').find({'i' => {'$gte' => 67}}).count
|
data/test/mongo-qa/dbs
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
if $DEBUG
|
7
|
-
3.times { |i| db.drop_collection("dbs_#{i+1}") }
|
8
|
-
end
|
9
|
-
|
10
|
-
def print_dbs_names(db)
|
11
|
-
db.collection_names.select{ |n| n =~ /\.dbs/ }.sort.each { |name|
|
12
|
-
puts name.sub(/^#{db.name}\./, '')
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
db.collection('dbs_1').insert('foo' => 'bar')
|
17
|
-
db.collection('dbs_2').insert('psi' => 'phi')
|
18
|
-
puts db.name
|
19
|
-
print_dbs_names(db)
|
20
|
-
db.drop_collection('dbs_1')
|
21
|
-
db.create_collection('dbs_3')
|
22
|
-
print_dbs_names(db)
|
data/test/mongo-qa/find
DELETED
data/test/mongo-qa/find1
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
if $DEBUG
|
7
|
-
db.drop_collection('c')
|
8
|
-
c = db.collection('c')
|
9
|
-
(5..15).each { |i| c.insert(:x => 0, :y => i, :z => (i+64).chr) }
|
10
|
-
(1..50).each { |i| c.insert(:x => 1, :y => i, :z => (i+64).chr) }
|
11
|
-
(5..15).each { |i| c.insert(:x => 2, :y => i, :z => (i+64).chr) }
|
12
|
-
end
|
13
|
-
|
14
|
-
cursor = db.collection('c').find({'x' => 1}, :sort => 'y', :skip => 20, :limit => 10)
|
15
|
-
cursor.each { |row| puts row['z'] }
|
data/test/mongo-qa/gridfs_in
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
|
5
|
-
require 'mongo/gridfs'
|
6
|
-
include GridFS
|
7
|
-
|
8
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
9
|
-
|
10
|
-
input_file = ARGV[0]
|
11
|
-
|
12
|
-
File.open(input_file, "r") { |f|
|
13
|
-
GridStore.open(db, input_file, "w") { |g|
|
14
|
-
g.write(f.read)
|
15
|
-
}
|
16
|
-
}
|
data/test/mongo-qa/gridfs_out
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
|
5
|
-
require 'mongo/gridfs'
|
6
|
-
include GridFS
|
7
|
-
|
8
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
9
|
-
|
10
|
-
input_file = ARGV[0]
|
11
|
-
output_file = ARGV[1]
|
12
|
-
|
13
|
-
File.open(output_file, "w") { |f|
|
14
|
-
GridStore.open(db, input_file, "r") { |g|
|
15
|
-
f.write(g.read)
|
16
|
-
}
|
17
|
-
}
|
data/test/mongo-qa/indices
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
|
5
|
-
include Mongo
|
6
|
-
|
7
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
8
|
-
x = db.collection('x')
|
9
|
-
y = db.collection('y')
|
10
|
-
|
11
|
-
def sorted_index_info(c)
|
12
|
-
c.index_information.sort { |a,b| a[:name] <=> b[:name] }
|
13
|
-
end
|
14
|
-
|
15
|
-
def sorted_info_keys(info)
|
16
|
-
info[:keys].keys.sort.collect { |key| "#{key}_1" }.join("_")
|
17
|
-
end
|
18
|
-
|
19
|
-
def check_keys(c, expected)
|
20
|
-
keys = sorted_index_info(c).collect {|info| sorted_info_keys(info)}
|
21
|
-
if keys == expected
|
22
|
-
''
|
23
|
-
else
|
24
|
-
"#{c.name} indices should start out #{expected.inspect} but is #{keys.inspect}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
if $DEBUG
|
29
|
-
x.drop # also drops indexes
|
30
|
-
x.insert('field1' => 'f1', 'field2' => 'f2')
|
31
|
-
x.create_index('field1_1', 'field1')
|
32
|
-
x.create_index('field2_1', 'field2')
|
33
|
-
y.drop
|
34
|
-
end
|
35
|
-
|
36
|
-
# There should only be two indices on x, and none on y. We raise an error if
|
37
|
-
# the preconditions are not met. (They were not, on our testing harness, for a
|
38
|
-
# while due to Mongo behavior.)
|
39
|
-
err = []
|
40
|
-
err << check_keys(x, ['field1_1', 'field2_1'])
|
41
|
-
err << check_keys(y, [])
|
42
|
-
raise "\n#{err.join("\n")}" unless err == ['', '']
|
43
|
-
|
44
|
-
x.drop_index('field1_1')
|
45
|
-
sorted_index_info(x).each { |info| puts sorted_info_keys(info) }
|
46
|
-
|
47
|
-
y.create_index([['a', ASCENDING], ['b', ASCENDING], ['c', ASCENDING]])
|
48
|
-
y.create_index('d')
|
49
|
-
sorted_index_info(y).each { |info| puts sorted_info_keys(info) }
|
data/test/mongo-qa/remove
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
|
6
|
-
if $DEBUG
|
7
|
-
c = db.collection('remove1')
|
8
|
-
c.clear
|
9
|
-
50.times { |i| c.insert(:a => i) }
|
10
|
-
c = db.collection('remove2')
|
11
|
-
c.clear
|
12
|
-
c.insert(:a => 3, :b => 1)
|
13
|
-
c.insert(:a => 3, :b => 3)
|
14
|
-
c.insert(:a => 2, :b => 3)
|
15
|
-
c.insert(:b => 3)
|
16
|
-
end
|
17
|
-
|
18
|
-
db.collection('remove1').clear
|
19
|
-
db.collection('remove2').remove('a' => 3)
|
20
|
-
|
21
|
-
if $DEBUG
|
22
|
-
puts "remove1 count = #{db.collection('remove1').count}"
|
23
|
-
puts "remove2 count = #{db.collection('remove2').count}"
|
24
|
-
db.collection('remove2').find.each { |row| puts row.inspect }
|
25
|
-
end
|
data/test/mongo-qa/stress1
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
LONG_STRING = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" * 6
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
6
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
7
|
-
c = db.collection('stress1')
|
8
|
-
|
9
|
-
n1 = 50_000
|
10
|
-
n2 = 10_000
|
11
|
-
|
12
|
-
if $DEBUG
|
13
|
-
n1 = 5
|
14
|
-
n2 = 1
|
15
|
-
c.drop
|
16
|
-
end
|
17
|
-
|
18
|
-
n1.times { |i|
|
19
|
-
c.insert(:name => "asdf#{i}", :date => Time.now, :id => i,
|
20
|
-
:blah => LONG_STRING, :subarray => [])
|
21
|
-
}
|
22
|
-
puts
|
23
|
-
|
24
|
-
n2.times { |i|
|
25
|
-
x = c.find_one({:id => i})
|
26
|
-
x['subarray'] = "foo#{i}"
|
27
|
-
p x
|
28
|
-
c.modify({:id => i}, x)
|
29
|
-
}
|
30
|
-
puts
|
31
|
-
|
32
|
-
if $DEBUG
|
33
|
-
puts "stress1 has #{c.count} records"
|
34
|
-
c.find.each { |row| puts "#{row['id']}: #{row['subarray'].inspect}" }
|
35
|
-
end
|
data/test/mongo-qa/test1
DELETED
data/test/mongo-qa/update
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
|
-
foo = db.collection('foo')
|
6
|
-
|
7
|
-
if $DEBUG
|
8
|
-
foo.drop
|
9
|
-
foo.insert(:x => 1)
|
10
|
-
end
|
11
|
-
|
12
|
-
foo.modify({:x => 1}, {:x => 1, :y => 2})
|
13
|
-
foo.modify({:x => 2}, {:x => 1, :y => 7})
|
14
|
-
foo.repsert({:x => 3}, {:x => 4, :y => 1})
|
15
|
-
|
16
|
-
if $DEBUG
|
17
|
-
foo.find.each { |row| puts row.inspect }
|
18
|
-
end
|
data/test/test_message.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
class MessageTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@msg = Message.new(42)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_initial_info
|
14
|
-
assert_equal Message::HEADER_SIZE, @msg.buf.length
|
15
|
-
@msg.write_long(1029)
|
16
|
-
@msg.buf.rewind
|
17
|
-
assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
|
18
|
-
@msg.buf.get_int # skip message id
|
19
|
-
assert_equal 0, @msg.buf.get_int
|
20
|
-
assert_equal 42, @msg.buf.get_int
|
21
|
-
assert_equal 1029, @msg.buf.get_long
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_update_length
|
25
|
-
@msg.update_message_length
|
26
|
-
@msg.buf.rewind
|
27
|
-
assert_equal Message::HEADER_SIZE, @msg.buf.get_int
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_long_length
|
31
|
-
@msg.write_long(1027)
|
32
|
-
assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|