mongodb-mongo 0.11 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -67,6 +67,11 @@ module XGen
67
67
  # ascending, -1 == descending, or array of field names (all
68
68
  # assumed to be sorted in ascending order).
69
69
  # :hint :: See #hint. This option overrides the collection-wide value.
70
+ # :snapshot :: If true, snapshot mode will be used for this query.
71
+ # Snapshot mode assures no duplicates are returned, or
72
+ # objects missed, which were preset at both the start and
73
+ # end of the query's execution. For details see
74
+ # http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database
70
75
  def find(selector={}, options={})
71
76
  fields = options.delete(:fields)
72
77
  fields = nil if fields && fields.empty?
@@ -74,13 +79,14 @@ module XGen
74
79
  limit = options.delete(:limit) || 0
75
80
  sort = options.delete(:sort)
76
81
  hint = options.delete(:hint)
82
+ snapshot = options.delete(:snapshot)
77
83
  if hint
78
84
  hint = normalize_hint_fields(hint)
79
85
  else
80
86
  hint = @hint # assumed to be normalized already
81
87
  end
82
88
  raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty?
83
- @db.query(self, Query.new(selector, fields, offset, limit, sort, hint))
89
+ @db.query(self, Query.new(selector, fields, offset, limit, sort, hint, snapshot))
84
90
  end
85
91
 
86
92
  # Find the first record that matches +selector+. See #find.
@@ -62,7 +62,7 @@ module XGen
62
62
  end
63
63
  sel['$hint'] = query.hint if query.hint && query.hint.length > 0
64
64
  sel['$explain'] = true if query.explain
65
-
65
+ sel['$snapshot'] = true if query.snapshot
66
66
  end
67
67
  write_doc(sel)
68
68
  write_doc(query.fields) if query.fields
data/lib/mongo/query.rb CHANGED
@@ -26,7 +26,7 @@ module XGen
26
26
  # Mongo documentation for query details.
27
27
  class Query
28
28
 
29
- attr_accessor :number_to_skip, :number_to_return, :order_by
29
+ attr_accessor :number_to_skip, :number_to_return, :order_by, :snapshot
30
30
  # If true, $explain will be set in QueryMessage that uses this query.
31
31
  attr_accessor :explain
32
32
  # Either +nil+ or a hash (preferably an OrderedHash).
@@ -63,9 +63,9 @@ module XGen
63
63
  # hint :: If not +nil+, specifies query hint fields. Must be either
64
64
  # +nil+ or a hash (preferably an OrderedHash). See
65
65
  # Collection#hint.
66
- def initialize(sel={}, return_fields=nil, number_to_skip=0, number_to_return=0, order_by=nil, hint=nil)
67
- @number_to_skip, @number_to_return, @order_by, @hint =
68
- number_to_skip, number_to_return, order_by, hint
66
+ def initialize(sel={}, return_fields=nil, number_to_skip=0, number_to_return=0, order_by=nil, hint=nil, snapshot=nil)
67
+ @number_to_skip, @number_to_return, @order_by, @hint, @snapshot =
68
+ number_to_skip, number_to_return, order_by, hint, snapshot
69
69
  @explain = nil
70
70
  self.selector = sel
71
71
  self.fields = return_fields
@@ -111,7 +111,7 @@ module XGen
111
111
  end
112
112
 
113
113
  def contains_special_fields
114
- (@order_by != nil && @order_by.length > 0) || @explain || @hint
114
+ (@order_by != nil && @order_by.length > 0) || @explain || @hint || @snapshot
115
115
  end
116
116
  end
117
117
  end
@@ -80,7 +80,7 @@ TEST_FILES = ['tests/mongo-qa/_common.rb',
80
80
 
81
81
  Gem::Specification.new do |s|
82
82
  s.name = 'mongo'
83
- s.version = '0.11'
83
+ s.version = '0.11.1'
84
84
  s.platform = Gem::Platform::RUBY
85
85
  s.summary = 'Ruby driver for the 10gen Mongo DB'
86
86
  s.description = 'A Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
data/tests/test_db_api.rb CHANGED
@@ -46,6 +46,15 @@ class DBAPITest < Test::Unit::TestCase
46
46
  assert docs.detect { |row| row['b'] == 4 }
47
47
  end
48
48
 
49
+ def test_save_ordered_hash
50
+ oh = OrderedHash.new
51
+ oh['a'] = -1
52
+ oh['b'] = 'foo'
53
+
54
+ oid = @@coll.save(oh)
55
+ assert_equal 'foo', @@coll.find_first(:_id => oid)['b']
56
+ end
57
+
49
58
  def test_insert_multiple
50
59
  ids = @@coll.insert({'a' => 2}, {'b' => 3})
51
60
 
@@ -781,6 +790,14 @@ class DBAPITest < Test::Unit::TestCase
781
790
  assert_equal 0, b.count()
782
791
  end
783
792
 
793
+ # doesn't really test functionality, just that the option is set correctly
794
+ def test_snapshot
795
+ @@db.collection("test").find({}, :snapshot => true).to_a
796
+ assert_raise RuntimeError do
797
+ @@db.collection("test").find({}, :snapshot => true, :sort => 'a').to_a
798
+ end
799
+ end
800
+
784
801
  # TODO this test fails with error message "Undefed Before end of object"
785
802
  # That is a database error. The undefined type may go away.
786
803
 
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.11"
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard