mongo 1.12.0.rc1 → 1.12.0.rc2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c40b2e0b36d1dab70bbf23b20961b950469a640
4
- data.tar.gz: e5c58505d9876a76b88ad649292e2472b78c5d4d
3
+ metadata.gz: 07c50e679638684c8277ec5ddd42f271cce1483e
4
+ data.tar.gz: e64b8dc7593cb392f7b5cbefec0d8a4f3e762579
5
5
  SHA512:
6
- metadata.gz: e35166ca0624f7b166f2761ee67b166a2c4e7893c317452c529d04e270f03d986b76c22138f5b32546ef5decea0fc4f24fb26bea066ba8bdc6e0245f62727ec4
7
- data.tar.gz: 6b49f4cceb3e1ecafe5cbaaa5e0c7a54ae295735e43d9b36cf0ad88d1167165190215468d3eccce6d57d21c9f1e904bec35167af289f2c1590ebb3df44c7b2b9
6
+ metadata.gz: 75165e8744c3f9429898d168bbc22a454942511fb6eae921e8191ea851fb4f307a59eab075d4cfc14bbc299e4852a1865be48a6bce40a077f81612f5f4162597
7
+ data.tar.gz: 78d4dedec4689c70597d4ddaed620e43d57c0fa24fd48a6ea2ea53f182026faebb980dec2dcbfb1ffdc53fc666cae322f377733a18e96e248553bea166371044
Binary file
data.tar.gz.sig CHANGED
Binary file
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.12.0.rc1
1
+ 1.12.0.rc2
@@ -729,7 +729,8 @@ module Mongo
729
729
  seed = {
730
730
  :cursor_id => cursor_info['id'],
731
731
  :first_batch => cursor_info['firstBatch'],
732
- :pool => pinned_pool
732
+ :pool => pinned_pool,
733
+ :ns => cursor_info['ns']
733
734
  }
734
735
 
735
736
  return Cursor.new(self, seed.merge!(opts))
@@ -901,7 +902,8 @@ module Mongo
901
902
  seed = {
902
903
  :cursor_id => cursor_info['cursor']['id'],
903
904
  :first_batch => cursor_info['cursor']['firstBatch'],
904
- :pool => pinned_pool
905
+ :pool => pinned_pool,
906
+ :ns => cursor_info['ns']
905
907
  }
906
908
  Cursor.new(self, seed.merge!(opts))
907
909
  end
@@ -23,8 +23,7 @@ module Mongo
23
23
  include Mongo::ReadPreference
24
24
 
25
25
  attr_reader :collection, :selector, :fields,
26
- :order, :hint, :snapshot, :timeout,
27
- :full_collection_name, :transformer,
26
+ :order, :hint, :snapshot, :timeout, :transformer,
28
27
  :options, :cursor_id, :show_disk_loc,
29
28
  :comment, :compile_regex, :read, :tag_sets,
30
29
  :acceptable_latency
@@ -40,6 +39,7 @@ module Mongo
40
39
  @cursor_id = opts.delete(:cursor_id)
41
40
  @db = collection.db
42
41
  @collection = collection
42
+ @ns = opts.delete(:ns)
43
43
  @connection = @db.connection
44
44
  @logger = @connection.logger
45
45
 
@@ -83,7 +83,6 @@ module Mongo
83
83
 
84
84
  batch_size(opts.delete(:batch_size) || 0)
85
85
 
86
- @full_collection_name = "#{@collection.db.name}.#{@collection.name}"
87
86
  @cache = opts.delete(:first_batch) || []
88
87
  @returned = 0
89
88
 
@@ -124,6 +123,10 @@ module Mongo
124
123
  @cursor_id && @cursor_id != 0
125
124
  end
126
125
 
126
+ def full_collection_name
127
+ @ns || "#{@collection.db.name}.#{@collection.name}"
128
+ end
129
+
127
130
  # Get the next document specified the cursor options.
128
131
  #
129
132
  # @return [Hash, Nil] the next document or Nil if no documents remain.
@@ -484,7 +487,7 @@ module Mongo
484
487
 
485
488
  # Clean output for inspect.
486
489
  def inspect
487
- "<Mongo::Cursor:0x#{object_id.to_s(16)} namespace='#{@db.name}.#{@collection.name}' " +
490
+ "<Mongo::Cursor:0x#{object_id.to_s(16)} namespace='#{full_collection_name}' " +
488
491
  "@selector=#{@selector.inspect} @cursor_id=#{@cursor_id}>"
489
492
  end
490
493
 
@@ -580,7 +583,7 @@ module Mongo
580
583
  message = BSON::ByteBuffer.new([0, 0, 0, 0])
581
584
 
582
585
  # DB name.
583
- BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
586
+ BSON::BSON_RUBY.serialize_cstr(message, full_collection_name)
584
587
 
585
588
  # Number of results to return.
586
589
  if @limit > 0
@@ -636,7 +639,7 @@ module Mongo
636
639
  def construct_query_message
637
640
  message = BSON::ByteBuffer.new("", @connection.max_bson_size + MongoClient::COMMAND_HEADROOM)
638
641
  message.put_int(@options)
639
- BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
642
+ BSON::BSON_RUBY.serialize_cstr(message, full_collection_name)
640
643
  message.put_int(@skip)
641
644
  @batch_size > 1 ? message.put_int(@batch_size) : message.put_int(@limit)
642
645
  if query_contains_special_fields? && @bson # costs two serialize calls
@@ -289,7 +289,23 @@ module Mongo
289
289
  if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8)
290
290
  cmd = BSON::OrderedHash[:listCollections, 1]
291
291
  cmd.merge!(:filter => { :name => coll_name }) if coll_name
292
- self.command(cmd)['collections']
292
+ result = self.command(cmd, :cursor => {})
293
+ if result.key?('cursor')
294
+ cursor_info = result['cursor']
295
+ pinned_pool = @client.pinned_pool
296
+ pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys)
297
+
298
+ seed = {
299
+ :cursor_id => cursor_info['id'],
300
+ :first_batch => cursor_info['firstBatch'],
301
+ :pool => pinned_pool,
302
+ :ns => cursor_info['ns']
303
+ }
304
+
305
+ Cursor.new(Collection.new('$cmd', self), seed).to_a
306
+ else
307
+ result['collections']
308
+ end
293
309
  else
294
310
  legacy_collections_info(coll_name).to_a
295
311
  end
@@ -493,11 +509,27 @@ module Mongo
493
509
  # defining the index.
494
510
  def index_information(collection_name)
495
511
  if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8)
496
- result = self.command(:listIndexes => collection_name)['indexes']
512
+ result = self.command({ :listIndexes => collection_name }, :cursor => {})
513
+ if result.key?('cursor')
514
+ cursor_info = result['cursor']
515
+ pinned_pool = @client.pinned_pool
516
+ pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys)
517
+
518
+ seed = {
519
+ :cursor_id => cursor_info['id'],
520
+ :first_batch => cursor_info['firstBatch'],
521
+ :pool => pinned_pool,
522
+ :ns => cursor_info['ns']
523
+ }
524
+
525
+ indexes = Cursor.new(Collection.new('$cmd', self), seed).to_a
526
+ else
527
+ indexes = result['indexes']
528
+ end
497
529
  else
498
- result = legacy_list_indexes(collection_name)
530
+ indexes = legacy_list_indexes(collection_name)
499
531
  end
500
- result.reduce({}) do |info, index|
532
+ indexes.reduce({}) do |info, index|
501
533
  info.merge!(index['name'] => index)
502
534
  end
503
535
  end
@@ -589,6 +621,9 @@ module Mongo
589
621
  end.join('; ')
590
622
  message << ').'
591
623
  code = result['code'] || result['assertionCode']
624
+ if result['writeErrors']
625
+ code = result['writeErrors'].first['code']
626
+ end
592
627
  raise ExecutionTimeout.new(message, code, result) if code == MAX_TIME_MS_CODE
593
628
  raise OperationFailure.new(message, code, result)
594
629
  end
@@ -345,6 +345,18 @@ class CollectionTest < Test::Unit::TestCase
345
345
  end
346
346
  end
347
347
 
348
+ def test_error_code
349
+ coll = @db['test-error-code']
350
+ coll.ensure_index(BSON::OrderedHash[:x, Mongo::ASCENDING], { :unique => true })
351
+ coll.save(:x => 2)
352
+ begin
353
+ coll.save(:x => 2)
354
+ rescue => ex
355
+ assert_not_nil ex.error_code
356
+ end
357
+ coll.drop
358
+ end
359
+
348
360
  def test_aggregation_cursor
349
361
  return unless @version >= '2.5.1'
350
362
  [10, 1000].each do |size|
@@ -468,21 +468,19 @@ class CursorTest < Test::Unit::TestCase
468
468
  def test_kill_cursors
469
469
  @coll.drop
470
470
 
471
- client_cursors = @db.command("cursorInfo" => 1)["clientCursors_size"]
471
+ client_cursors = cursor_count(@db)
472
472
 
473
473
  10000.times do |i|
474
474
  @coll.insert("i" => i)
475
475
  end
476
476
 
477
- assert_equal(client_cursors,
478
- @db.command("cursorInfo" => 1)["clientCursors_size"])
477
+ assert_equal(client_cursors, cursor_count(@db))
479
478
 
480
479
  10.times do |i|
481
480
  @coll.find_one()
482
481
  end
483
482
 
484
- assert_equal(client_cursors,
485
- @db.command("cursorInfo" => 1)["clientCursors_size"])
483
+ assert_equal(client_cursors, cursor_count(@db))
486
484
 
487
485
  10.times do |i|
488
486
  a = @coll.find()
@@ -490,38 +488,32 @@ class CursorTest < Test::Unit::TestCase
490
488
  a.close()
491
489
  end
492
490
 
493
- assert_equal(client_cursors,
494
- @db.command("cursorInfo" => 1)["clientCursors_size"])
491
+ assert_equal(client_cursors, cursor_count(@db))
495
492
 
496
493
  a = @coll.find()
497
494
  a.next_document
498
495
 
499
- assert_not_equal(client_cursors,
500
- @db.command("cursorInfo" => 1)["clientCursors_size"])
496
+ assert_not_equal(client_cursors, cursor_count(@db))
501
497
 
502
498
  a.close()
503
499
 
504
- assert_equal(client_cursors,
505
- @db.command("cursorInfo" => 1)["clientCursors_size"])
500
+ assert_equal(client_cursors, cursor_count(@db))
506
501
 
507
502
  a = @coll.find({}, :limit => 10).next_document
508
503
 
509
- assert_equal(client_cursors,
510
- @db.command("cursorInfo" => 1)["clientCursors_size"])
504
+ assert_equal(client_cursors, cursor_count(@db))
511
505
 
512
506
  @coll.find() do |cursor|
513
507
  cursor.next_document
514
508
  end
515
509
 
516
- assert_equal(client_cursors,
517
- @db.command("cursorInfo" => 1)["clientCursors_size"])
510
+ assert_equal(client_cursors, cursor_count(@db))
518
511
 
519
512
  @coll.find() { |cursor|
520
513
  cursor.next_document
521
514
  }
522
515
 
523
- assert_equal(client_cursors,
524
- @db.command("cursorInfo" => 1)["clientCursors_size"])
516
+ assert_equal(client_cursors, cursor_count(@db))
525
517
  end
526
518
 
527
519
  def test_count_with_fields
@@ -680,4 +672,12 @@ class CursorTest < Test::Unit::TestCase
680
672
  assert_instance_of(klass, instance)
681
673
  end
682
674
  end
675
+
676
+ def cursor_count(db)
677
+ if @version > '2.6.0'
678
+ db.command("serverStatus" => 1)["metrics"]["cursor"]["open"]["total"]
679
+ else
680
+ db.command("cursorInfo" => 1)["clientCursors_size"]
681
+ end
682
+ end
683
683
  end
@@ -138,7 +138,15 @@ class CursorUnitTest < Test::Unit::TestCase
138
138
  assert_equal 100, @cursor.batch_size
139
139
  end
140
140
 
141
- context "conected to mongos" do
141
+ context 'when an alternate namespace is specified' do
142
+
143
+ should 'use the alternate namespace' do
144
+ cursor = Cursor.new(@collection, :ns => 'other_db.other_collection')
145
+ assert_equal('other_db.other_collection', cursor.full_collection_name)
146
+ end
147
+ end
148
+
149
+ context "connected to mongos" do
142
150
  setup do
143
151
  @connection.stubs(:mongos?).returns(true)
144
152
  @tag_sets = [{:dc => "ny"}]
@@ -211,7 +219,7 @@ class CursorUnitTest < Test::Unit::TestCase
211
219
  end
212
220
  end
213
221
 
214
- context "not conected to mongos" do
222
+ context "not connected to mongos" do
215
223
  setup do
216
224
  @connection.stubs(:mongos?).returns(false)
217
225
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0.rc1
4
+ version: 1.12.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Stolfo
@@ -34,7 +34,7 @@ cert_chain:
34
34
  JrZM8w8wGbIOeLtoQqa7HB/jOYbTahH7KMNh2LHAbOR93hNIJxVRa4iwxiMQ75tN
35
35
  9WUIAJ4AEtjwRg1Bz0OwDo3aucPCBpx77+/FWhv7JYY=
36
36
  -----END CERTIFICATE-----
37
- date: 2014-12-03 00:00:00.000000000 Z
37
+ date: 2014-12-19 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bson
@@ -42,14 +42,14 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.12.0.rc1
45
+ version: 1.12.0.rc2
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - '='
51
51
  - !ruby/object:Gem::Version
52
- version: 1.12.0.rc1
52
+ version: 1.12.0.rc2
53
53
  description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
54
54
  email: mongodb-dev@googlegroups.com
55
55
  executables:
metadata.gz.sig CHANGED
Binary file