mongodb-mongo 0.5.3 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,14 @@
3
3
  require File.join(File.dirname(__FILE__), '_common.rb')
4
4
  db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
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
+
6
14
  puts db.collection('test1').count
7
15
  puts db.collection('test2').count
8
16
  puts db.collection('test3').count('i' => 'a')
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '_common.rb')
4
+ db = Mongo.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/tests/mongo-qa/find CHANGED
@@ -3,4 +3,8 @@
3
3
  require File.join(File.dirname(__FILE__), '_common.rb')
4
4
  db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
5
 
6
+ if $DEBUG
7
+ db.drop_collection('test')
8
+ end
9
+
6
10
  db.collection('test').insert('a' => 2)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '_common.rb')
4
+ db = Mongo.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', :offset => 20, :limit => 10)
15
+ cursor.each { |row| puts row['z'] }
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '_common.rb')
4
+ db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
+ x = db.collection('x')
6
+ y = db.collection('y')
7
+
8
+ def sorted_index_info(c)
9
+ c.index_information.sort { |a,b| a[:name] <=> b[:name] }
10
+ end
11
+
12
+ def sorted_info_keys(info)
13
+ info[:keys].keys.sort.collect { |key| "#{key}_1" }.join("_")
14
+ end
15
+
16
+ def check_keys(c, expected)
17
+ keys = sorted_index_info(c).collect {|info| sorted_info_keys(info)}
18
+ if keys == expected
19
+ ''
20
+ else
21
+ "#{c.name} indices should start out #{expected.inspect} but is #{keys.inspect}"
22
+ end
23
+ end
24
+
25
+ if $DEBUG
26
+ x.drop # also drops indexes
27
+ x.insert('field1' => 'f1', 'field2' => 'f2')
28
+ x.create_index('field1_1', 'field1')
29
+ x.create_index('field2_1', 'field2')
30
+ y.drop
31
+ end
32
+
33
+ # There should only be two indices on x, and none on y. We raise an error if
34
+ # the preconditions are not met. (They were not, on our testing harness, for a
35
+ # while due to Mongo behavior.)
36
+ err = []
37
+ err << check_keys(x, ['field1_1', 'field2_1'])
38
+ err << check_keys(y, [])
39
+ raise "\n#{err.join("\n")}" unless err == ['', '']
40
+
41
+ x.drop_index('field1_1')
42
+ sorted_index_info(x).each { |info| puts sorted_info_keys(info) }
43
+
44
+ y.create_index('abc', ['a', 'b', 'c'])
45
+ y.create_index('d', ['d'])
46
+ sorted_index_info(y).each { |info| puts sorted_info_keys(info) }
@@ -3,5 +3,23 @@
3
3
  require File.join(File.dirname(__FILE__), '_common.rb')
4
4
  db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
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
+
6
18
  db.collection('remove1').clear
7
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
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ LONG_STRING = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" * 6
4
+
5
+ require File.join(File.dirname(__FILE__), '_common.rb')
6
+ db = Mongo.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_first({: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/tests/mongo-qa/test1 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require File.join(File.dirname(__FILE__), '_common.rb')
4
4
  db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
-
6
5
  coll = db.collection('part1')
6
+
7
+ if $DEBUG
8
+ coll.drop
9
+ end
10
+
7
11
  100.times { |i| coll.insert('x' => i) }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '_common.rb')
4
+ db = Mongo.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/tests/test_db.rb CHANGED
@@ -67,14 +67,14 @@ class DBTest < Test::Unit::TestCase
67
67
 
68
68
  # new id gets added to returned object
69
69
  obj = coll.insert('name' => 'Fred', 'age' => 42)
70
- row = coll.find({'name' => 'Fred'}, :limit => 1).next_object
70
+ row = coll.find_first({'name' => 'Fred'}, :limit => 1)
71
71
  oid = row['_id']
72
72
  assert_not_nil oid
73
73
  assert_equal obj, row
74
74
 
75
75
  oid = XGen::Mongo::Driver::ObjectID.new
76
76
  obj = coll.insert('_id' => oid, 'name' => 'Barney', 'age' => 41)
77
- row = coll.find({'name' => 'Barney'}, :limit => 1).next_object
77
+ row = coll.find_first({'name' => 'Barney'}, :limit => 1)
78
78
  db_oid = row['_id']
79
79
  assert_equal oid, db_oid
80
80
  assert_equal obj, row
data/tests/test_db_api.rb CHANGED
@@ -216,6 +216,18 @@ class DBAPITest < Test::Unit::TestCase
216
216
  assert_equal 4, docs.size
217
217
  end
218
218
 
219
+ def test_find_first
220
+ x = @@coll.find_first('a' => 1)
221
+ assert_not_nil x
222
+ assert_equal 1, x['a']
223
+ end
224
+
225
+ def test_find_first_no_records
226
+ @@coll.clear
227
+ x = @@coll.find_first('a' => 1)
228
+ assert_nil x
229
+ end
230
+
219
231
  def test_drop_collection
220
232
  assert @@db.drop_collection(@@coll.name), "drop of collection #{@@coll.name} failed"
221
233
  assert !@@db.collection_names.include?(@@coll_full_name)
@@ -73,14 +73,14 @@ class ObjectIDTest < Test::Unit::TestCase
73
73
  assert_equal @o.to_s, o2.to_s
74
74
  end
75
75
 
76
- def test_legal_oid_string
77
- assert !ObjectID.legal_oid_string(nil)
78
- assert !ObjectID.legal_oid_string("fred")
79
- assert !ObjectID.legal_oid_string("0000")
80
- assert !ObjectID.legal_oid_string('000102030405060708090A0')
81
- assert ObjectID.legal_oid_string('000102030405060708090A0B')
82
- assert ObjectID.legal_oid_string('abcdefABCDEF123456789012')
83
- assert !ObjectID.legal_oid_string('abcdefABCDEF12345678901x')
76
+ def test_legal
77
+ assert !ObjectID.legal?(nil)
78
+ assert !ObjectID.legal?("fred")
79
+ assert !ObjectID.legal?("0000")
80
+ assert !ObjectID.legal?('000102030405060708090A0')
81
+ assert ObjectID.legal?('000102030405060708090A0B')
82
+ assert ObjectID.legal?('abcdefABCDEF123456789012')
83
+ assert !ObjectID.legal?('abcdefABCDEF12345678901x')
84
84
  end
85
85
 
86
86
  def test_from_string_leading_zeroes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-03 00:00:00 -08:00
12
+ date: 2009-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,13 +22,24 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.rdoc
24
24
  files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - mongo-ruby-driver.gemspec
25
28
  - bin/mongo_console
26
29
  - bin/run_test_script
30
+ - bin/standard_benchmark
31
+ - examples/admin.rb
27
32
  - examples/benchmarks.rb
28
33
  - examples/blog.rb
34
+ - examples/capped.rb
35
+ - examples/cursor.rb
36
+ - examples/gridfs.rb
29
37
  - examples/index_test.rb
38
+ - examples/info.rb
39
+ - examples/queries.rb
30
40
  - examples/simple.rb
31
- - lib/mongo.rb
41
+ - examples/strict.rb
42
+ - examples/types.rb
32
43
  - lib/mongo/admin.rb
33
44
  - lib/mongo/collection.rb
34
45
  - lib/mongo/cursor.rb
@@ -58,9 +69,7 @@ files:
58
69
  - lib/mongo/util/byte_buffer.rb
59
70
  - lib/mongo/util/ordered_hash.rb
60
71
  - lib/mongo/util/xml_to_ruby.rb
61
- - README.rdoc
62
- - Rakefile
63
- - mongo-ruby-driver.gemspec
72
+ - lib/mongo.rb
64
73
  has_rdoc: true
65
74
  homepage: http://www.mongodb.org
66
75
  post_install_message:
@@ -91,12 +100,17 @@ specification_version: 2
91
100
  summary: Simple pure-Ruby driver for the 10gen Mongo DB
92
101
  test_files:
93
102
  - tests/mongo-qa/_common.rb
103
+ - tests/mongo-qa/admin
94
104
  - tests/mongo-qa/capped
95
- - tests/mongo-qa/circular
96
105
  - tests/mongo-qa/count1
106
+ - tests/mongo-qa/dbs
97
107
  - tests/mongo-qa/find
108
+ - tests/mongo-qa/find1
109
+ - tests/mongo-qa/indices
98
110
  - tests/mongo-qa/remove
111
+ - tests/mongo-qa/stress1
99
112
  - tests/mongo-qa/test1
113
+ - tests/mongo-qa/update
100
114
  - tests/test_admin.rb
101
115
  - tests/test_bson.rb
102
116
  - tests/test_byte_buffer.rb
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), '_common.rb')
4
- db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
5
-
6
- colla = db.collection('a')
7
- collb = db.collection('b')
8
- collc = db.collection('c')
9
-
10
- colla.insert('c' => 'b')
11
- collb.insert('c' => 1)
12
-
13
- x_id = ObjectID.new
14
- x_dbref = DBRef.new(nil, 'thiz', db, 'c', x_id)
15
- x = {'_id' => x_id, 'that' => 2, 'thiz' => x_dbref}
16
- collc.insert(x)