mongodb-mongo 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -48,6 +48,19 @@ you can install it as a gem from the source by typing
48
48
  Note: when you install the gem this way it is called "mongo", not
49
49
  "mongodb-mongo". In either case, you "require 'mongo'" in your source code.
50
50
 
51
+ === Optional C Extension
52
+
53
+ There is a separate gem containing optional C extensions that will increase the
54
+ performance of the driver. To use the optional extensions just install the gem
55
+ by typing
56
+
57
+ $ sudo gem install mongodb-mongo_ext
58
+
59
+ To install from source type this instead
60
+
61
+ $ rake gem:install_extensions
62
+
63
+ That's all there is to it!
51
64
 
52
65
  = Examples
53
66
 
data/Rakefile CHANGED
@@ -11,6 +11,9 @@ end
11
11
  require 'rbconfig'
12
12
  include Config
13
13
 
14
+ gem_command = "gem"
15
+ gem_command = "gem1.9" if CONFIG["MAJOR"] == "1" && CONFIG["MINOR"] == "9"
16
+
14
17
  # NOTE: some of the tests assume Mongo is running
15
18
  Rake::TestTask.new do |t|
16
19
  t.test_files = FileList['tests/test*.rb']
@@ -18,8 +21,10 @@ end
18
21
 
19
22
  desc "Generate documentation"
20
23
  task :rdoc do
21
- FileUtils.rm_rf('html')
22
- system "rdoc --main README.rdoc --op html --inline-source --quiet README.rdoc `find lib -name '*.rb'`"
24
+ version = eval(File.read("mongo-ruby-driver.gemspec")).version
25
+ out = File.join('html', version.to_s)
26
+ FileUtils.rm_rf(out)
27
+ system "rdoc --main README.rdoc --op #{out} --inline-source --quiet README.rdoc `find lib -name '*.rb'`"
23
28
  end
24
29
 
25
30
  desc "Publish documentation to mongo.rubyforge.org"
@@ -33,8 +38,8 @@ namespace :gem do
33
38
  desc "Install the gem locally"
34
39
  task :install do
35
40
  sh <<EOS
36
- gem build mongo-ruby-driver.gemspec &&
37
- sudo gem install mongo-*.gem &&
41
+ #{gem_command} build mongo-ruby-driver.gemspec &&
42
+ sudo #{gem_command} install mongo-*.gem &&
38
43
  rm mongo-*.gem
39
44
  EOS
40
45
  end
@@ -42,8 +47,8 @@ EOS
42
47
  desc "Install the optional c extensions"
43
48
  task :install_extensions do
44
49
  sh <<EOS
45
- gem build mongo-extensions.gemspec &&
46
- sudo gem install mongo_ext-*.gem &&
50
+ #{gem_command} build mongo-extensions.gemspec &&
51
+ sudo #{gem_command} install mongo_ext-*.gem &&
47
52
  rm mongo_ext-*.gem
48
53
  EOS
49
54
  end
@@ -52,8 +52,9 @@ end
52
52
  host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
53
53
  port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
54
54
 
55
- db = Mongo.new(host, port).db('ruby-benchmark')
56
- db.drop_collection('benchmark')
55
+ connection = Mongo.new(host, port)
56
+ connection.drop_database("benchmark")
57
+ db = connection.db('benchmark')
57
58
 
58
59
  insert = Proc.new { |coll, object, i|
59
60
  object['x'] = i
@@ -117,8 +117,10 @@ module XGen
117
117
  # should be either a single field name or a Array of [field name,
118
118
  # direction] pairs. Directions should be specified as
119
119
  # XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING.
120
- def create_index(field_or_spec)
121
- @db.create_index(@name, field_or_spec)
120
+ # +unique+ is an optional boolean indicating whether this index
121
+ # should enforce a uniqueness constraint.
122
+ def create_index(field_or_spec, unique=false)
123
+ @db.create_index(@name, field_or_spec, unique)
122
124
  end
123
125
 
124
126
  # Drop index +name+.
data/lib/mongo/db.rb CHANGED
@@ -239,8 +239,6 @@ module XGen
239
239
  def drop_collection(name)
240
240
  return true unless collection_names.include?(full_coll_name(name))
241
241
 
242
- coll = collection(name)
243
- coll.drop_indexes # Mongo requires that we drop indexes manually
244
242
  ok?(db_command(:drop => name))
245
243
  end
246
244
 
@@ -432,8 +430,9 @@ module XGen
432
430
  # should be either a single field name or a Array of [field name,
433
431
  # direction] pairs. Directions should be specified as
434
432
  # XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING. Normally called
435
- # by Collection#create_index.
436
- def create_index(collection_name, field_or_spec)
433
+ # by Collection#create_index. If +unique+ is true the index will
434
+ # enforce a uniqueness constraint.
435
+ def create_index(collection_name, field_or_spec, unique=false)
437
436
  field_h = OrderedHash.new
438
437
  if field_or_spec.is_a? String
439
438
  field_h[field_or_spec] = 1
@@ -444,7 +443,8 @@ module XGen
444
443
  sel = {
445
444
  :name => name,
446
445
  :ns => full_coll_name(collection_name),
447
- :key => field_h
446
+ :key => field_h,
447
+ :unique => unique
448
448
  }
449
449
  @semaphore.synchronize {
450
450
  send_to_db(InsertMessage.new(@name, SYSTEM_INDEX_COLLECTION, sel))
@@ -46,6 +46,7 @@ class BSON
46
46
  SYMBOL = 14
47
47
  CODE_W_SCOPE = 15
48
48
  NUMBER_INT = 16
49
+ TIMESTAMP = 17
49
50
  MAXKEY = 127
50
51
 
51
52
  if RUBY_VERSION >= '1.9'
@@ -199,6 +200,10 @@ class BSON
199
200
  when CODE_W_SCOPE
200
201
  key = deserialize_cstr(@buf)
201
202
  doc[key] = deserialize_code_w_scope_data(@buf)
203
+ when TIMESTAMP
204
+ key = deserialize_cstr(@buf)
205
+ doc[key] = [deserialize_number_int_data(@buf),
206
+ deserialize_number_int_data(@buf)]
202
207
  when EOO
203
208
  break
204
209
  else
@@ -20,6 +20,12 @@
20
20
  # Hash already keeps its keys ordered by order of insertion.
21
21
  class OrderedHash < Hash
22
22
 
23
+ def ==(other)
24
+ !other.nil? &&
25
+ keys == other.keys &&
26
+ values == other.values
27
+ end
28
+
23
29
  # We only need the body of this class if the RUBY_VERSION is before 1.9
24
30
  if RUBY_VERSION < '1.9'
25
31
 
@@ -35,12 +41,6 @@ class OrderedHash < Hash
35
41
  super(key, value)
36
42
  end
37
43
 
38
- def ==(other)
39
- !other.nil? &&
40
- keys == other.keys &&
41
- values == other.values
42
- end
43
-
44
44
  def each
45
45
  @ordered_keys ||= []
46
46
  @ordered_keys.each { |k| yield k, self[k] }
@@ -79,7 +79,7 @@ TEST_FILES = ['tests/mongo-qa/_common.rb',
79
79
 
80
80
  Gem::Specification.new do |s|
81
81
  s.name = 'mongo'
82
- s.version = '0.6.5'
82
+ s.version = '0.6.6'
83
83
  s.platform = Gem::Platform::RUBY
84
84
  s.summary = 'Ruby driver for the 10gen Mongo DB'
85
85
  s.description = 'A Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
data/tests/test_bson.rb CHANGED
@@ -181,6 +181,15 @@ class BSONTest < Test::Unit::TestCase
181
181
  assert_equal '_id', roundtrip.keys.first
182
182
  end
183
183
 
184
+ def test_timestamp
185
+ val = {"test" => [4, 20]}
186
+ assert_equal val, @b.deserialize([0x13, 0x00, 0x00, 0x00,
187
+ 0x11, 0x74, 0x65, 0x73,
188
+ 0x74, 0x00, 0x04, 0x00,
189
+ 0x00, 0x00, 0x14, 0x00,
190
+ 0x00, 0x00, 0x00])
191
+ end
192
+
184
193
  def test_do_not_change_original_object
185
194
  val = OrderedHash.new
186
195
  val['not_id'] = 1
data/tests/test_db_api.rb CHANGED
@@ -285,9 +285,9 @@ class DBAPITest < Test::Unit::TestCase
285
285
  name = @@db.create_index(@@coll.name, 'a')
286
286
  list = @@db.index_information(@@coll.name)
287
287
  assert_equal @@coll.index_information, list
288
- assert_equal 1, list.length
288
+ assert_equal 2, list.length
289
289
 
290
- info = list[0]
290
+ info = list[1]
291
291
  assert_equal name, 'a_1'
292
292
  assert_equal name, info[:name]
293
293
  assert_equal 1, info[:keys]['a']
@@ -298,9 +298,9 @@ class DBAPITest < Test::Unit::TestCase
298
298
  def test_multiple_index_cols
299
299
  name = @@db.create_index(@@coll.name, [['a', DESCENDING], ['b', ASCENDING], ['c', DESCENDING]])
300
300
  list = @@db.index_information(@@coll.name)
301
- assert_equal 1, list.length
301
+ assert_equal 2, list.length
302
302
 
303
- info = list[0]
303
+ info = list[1]
304
304
  assert_equal name, 'a_-1_b_1_c_-1'
305
305
  assert_equal name, info[:name]
306
306
  keys = info[:keys].keys
@@ -309,6 +309,28 @@ class DBAPITest < Test::Unit::TestCase
309
309
  @@db.drop_index(@@coll.name, name)
310
310
  end
311
311
 
312
+ def test_unique_index
313
+ @@db.drop_collection("blah")
314
+ test = @@db.collection("blah")
315
+ test.create_index("hello")
316
+
317
+ test.insert("hello" => "world")
318
+ test.insert("hello" => "mike")
319
+ test.insert("hello" => "world")
320
+ assert !@@db.error?
321
+
322
+ @@db.drop_collection("blah")
323
+ test = @@db.collection("blah")
324
+ test.create_index("hello", unique=true)
325
+
326
+ test.insert("hello" => "world")
327
+ test.insert("hello" => "mike")
328
+ test.insert("hello" => "world")
329
+ assert @@db.error?
330
+
331
+ @@db.drop_collection("blah")
332
+ end
333
+
312
334
  def test_array
313
335
  @@coll << {'b' => [1, 2, 3]}
314
336
  rows = @@coll.find({}, {:fields => ['b']}).to_a
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.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-02-25 00:00:00 -08:00
13
+ date: 2009-04-08 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16