jmongo 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jmongo (1.0.3)
4
+ jmongo (1.1.1)
5
5
  require_all (~> 1.2)
6
6
 
7
7
  GEM
data/README.txt CHANGED
@@ -6,92 +6,43 @@ lifting. Unfortunately, the performance of the pure ruby path under jruby is les
6
6
  stellar. Additionally, the C extension isn't compatible with jruby so we aren't able to take
7
7
  advantage of any native code boost.
8
8
 
9
- JMongo solves this problem by putting a thin ruby wrapper around the mongo-java-driver. The
9
+ JMongo solves this problem by putting a thin ruby wrapper around the 10gen mongo-java-driver. The
10
10
  goal is to provide a drop-in replacement for the mongo and bson gems along with complete
11
11
  API compatibility.
12
12
 
13
- The initial version of this gem only wraps enough functionality to cover my personal use-cases.
14
- I encourage project forking.
13
+ The repo was was forked from Chuck Remes's (now deleted) repo.
15
14
 
16
- INSTALLATION
17
- % gem build jmongo.gemspec
18
- % gem install jmongo-0.1.0.gem
15
+ INSTALLATION (from Rubygems.org)
16
+ % gem install jmongo
19
17
 
18
+ USAGE
19
+ * Use jruby with 1.9 compatibility turned on JRUBY_OPTS='--1.9'
20
20
 
21
21
  PROGRESS
22
- The following methods have been ported and have at least basic functionality.
23
-
24
- find
25
- - limit, skip and sort
26
- find_one
27
- last_status
28
- insert
29
-
30
- 2010-10-16, Guy Boertje ported the following...
31
-
32
- count
33
- update
34
- save
35
- find_and_modify
36
- create_index
37
- ensure_index
38
- drop_index
39
- drop_indexes
40
- drop_collection
41
- drop_database
42
- database_names
43
-
44
- Also the returned objects are BSON::OrderedHash objects to match those of the regular ruby mongo library
45
-
46
- rough benchmarks
47
-
48
- drop collection 'bm' before and after mongo run
49
-
50
- require 'rubygems'
51
- require 'jmongo'
52
- #require 'mongo'
53
- require 'benchmark'
54
- n = 500
55
- db = Mongo::Connection.new('127.0.0.1',37037).db('bm')
56
- coll = db.collection('bm')
57
- ids = []
58
- docs = []
59
- Benchmark.bm do |x|
60
- x.report("inserts:") do
61
- for i in 1..n
62
- d = {'n'=>i}
63
- ids << coll.insert(d)
64
- end
65
- end
66
- x.report("updates:") do
67
- ids.each do |id|
68
- coll.update({'_id'=>id},{'$set'=>{'a'=>'blah'}})
69
- end
70
- end
71
- s = {'n'=>{'$gt'=>0}}
72
- coll.find(s).each{|d| }
73
- coll.find(s).each{|d| }
74
- c = coll.find(s)
75
- x.report("after find all, iterate:") do
76
- c.each do |d|
77
- docs << d
78
- end
79
- end
80
- end
81
- db.drop_collection('bm')
82
-
83
- Results
84
-
85
- ruby --fast --server mongo_bm.rb
86
- user system total real
87
- inserts: 0.879000 0.000000 0.879000 ( 0.878000)
88
- updates: 0.711000 0.000000 0.711000 ( 0.711000)
89
- after find all, iterate: 0.243000 0.000000 0.243000 ( 0.243000)
90
-
91
- ruby --fast --server jmongo_bm.rb
92
- user system total real
93
- inserts: 0.489000 0.000000 0.489000 ( 0.489000)
94
- updates: 0.357000 0.000000 0.357000 ( 0.357000)
95
- after find all, iterate: 0.058000 0.000000 0.058000 ( 0.058000)
96
-
97
-
22
+ Almost all of the Ruby driver API is implemented
23
+
24
+ The the Ruby driver tests have been brought over and converted to be MiniTest based and
25
+ the collection and cursor test suites pass. NOTE: a few (2/3) tests have been skipped, you should look at
26
+ them to see if they affect you.
27
+
28
+ The Mongoid rspec functional suite runs 2607 examples with 28 failures when using JMongo
29
+ My Mongoid repo was forked after this commit (so newer funtionality/spec will be missing)
30
+ commit 6cc97092bc10535b8b65647a3d14b10ca1b94c8c
31
+ Author: Bernerd Schaefer <bj.schaefer@gmail.com>
32
+ Date: Tue Jun 28 12:59:34 2011 +0200
33
+
34
+ The failures are classed in this way:
35
+ * Different Exception class being raised for BSON invalid keys
36
+ * Managing Replica Sets directly
37
+ * Managing Connection Pools directly
38
+ * XML serialization
39
+ * Ruby RegExp to BSON encode and decode
40
+
41
+ I will fix these problems in due course
42
+
43
+ Please note that the java driver handles the Replica Sets and connection pools
44
+ If you are using Replica Sets and want to use JMongo you should be OK if you use a URI to connect.
45
+ JMongo lets the Java driver handle reading from slaves and writing to master, although YMMV as I have not
46
+ tested JMongo with Replica Sets yet.
47
+ If you intend to use the fsync=true uri option to imply safe=true on your queries, at the moment you will also
48
+ need to specify the w option in the uri. e.g. mongodb://0.0.0.0:27017/?fsync=true;w=1;
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jmongo'
3
- s.version = '1.1.0'
4
- s.date = '2011-10-03'
3
+ s.version = '1.1.1'
4
+ s.date = '2011-10-06'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ["Chuck Remes","Guy Boertje", "Lee Henson"]
7
7
  s.email = ["cremes@mac.com", "guyboertje@gmail.com", "lee.m.henson@gmail.com"]
@@ -37,7 +37,6 @@ Gem::Specification.new do |s|
37
37
  lib/jmongo/version.rb
38
38
  spec/jmongo_spec.rb
39
39
  spec/spec_helper.rb
40
- test-results.txt
41
40
  test/auxillary/1.4_features.rb
42
41
  test/auxillary/authentication_test.rb
43
42
  test/auxillary/autoreconnect_test.rb
@@ -219,7 +219,7 @@ module Mongo
219
219
  # will be raised on an error. Note that a safe check requires an extra
220
220
  # round-trip to the database.
221
221
  def save(doc, options={})
222
- save_document(doc, (options[:safe] || false))
222
+ save_document(doc, options[:safe])
223
223
  end
224
224
 
225
225
  # Insert one or more documents into the collection.
@@ -240,9 +240,8 @@ module Mongo
240
240
  def insert(doc_or_docs, options={})
241
241
  doc_or_docs = [doc_or_docs] unless doc_or_docs.kind_of?(Array)
242
242
  doc_or_docs.collect! { |doc| @pk_factory.create_pk(doc) }
243
- safe = (options[:safe] || false)
244
243
  continue = (options[:continue_on_error] || false)
245
- docs = insert_documents(doc_or_docs, safe, continue)
244
+ docs = insert_documents(doc_or_docs, options[:safe], continue)
246
245
  docs.size == 1 ? docs.first['_id'] : docs.collect{|doc| doc['_id']}
247
246
  end
248
247
  alias_method :<<, :insert
@@ -269,8 +268,7 @@ module Mongo
269
268
  #
270
269
  # @core remove remove-instance_method
271
270
  def remove(selector={}, options={})
272
- safe = (options[:safe] || false)
273
- remove_documents(selector,safe)
271
+ remove_documents(selector,options[:safe])
274
272
  end
275
273
 
276
274
  # Update a single document in this collection.
@@ -295,8 +293,7 @@ module Mongo
295
293
  # @core update update-instance_method
296
294
  def update(selector, document, options={})
297
295
  upsert, multi = !!(options[:upsert]), !!(options[:multi])
298
- safe = (options[:safe] || false)
299
- update_documents(selector, document, upsert, multi, safe)
296
+ update_documents(selector, document, upsert, multi, options[:safe])
300
297
  end
301
298
 
302
299
  # Create a new index.
@@ -76,7 +76,7 @@ module Mongo
76
76
  end
77
77
 
78
78
  def remove_documents(obj, safe=nil)
79
- concern = write_concern(safe)
79
+ concern = @db.write_concern(safe)
80
80
  wr = @j_collection.remove(to_dbobject(obj), concern)
81
81
  return from_dbobject(wr.last_error(concern)) if concern.call_get_last_error
82
82
  true
@@ -85,7 +85,7 @@ module Mongo
85
85
  ## Note: refactor when java driver fully supports continue_on_error
86
86
  def insert_documents(obj, safe=nil, continue_on_error=false)
87
87
  to_do = [obj].flatten
88
- concern = write_concern(safe)
88
+ concern = @db.write_concern(safe)
89
89
  if continue_on_error
90
90
  out = []
91
91
  to_do.each do |doc|
@@ -145,7 +145,7 @@ module Mongo
145
145
 
146
146
  def update_documents(selector, document, upsert=false, multi=false, safe=nil)
147
147
  begin
148
- @j_collection.update(to_dbobject(selector),to_dbobject(document), upsert, multi, write_concern(safe))
148
+ @j_collection.update(to_dbobject(selector),to_dbobject(document), upsert, multi, @db.write_concern(safe))
149
149
  rescue => ex
150
150
  if ex.message =~ /E11001/
151
151
  msg = "Failed to update document #{document.inspect}, duplicate key"
@@ -160,7 +160,7 @@ module Mongo
160
160
  def save_document(obj, safe=nil)
161
161
  @pk_factory.create_pk(obj)
162
162
  db_obj = to_dbobject(obj)
163
- concern = write_concern(safe)
163
+ concern = @db.write_concern(safe)
164
164
  begin
165
165
  @j_collection.save( db_obj, concern )
166
166
  rescue => ex
@@ -6,6 +6,24 @@ module Mongo
6
6
  SYSTEM_NAMESPACE_COLLECTION = "system.namespaces"
7
7
  SYSTEM_PROFILE_COLLECTION = "system.profile"
8
8
 
9
+ #@collection.save({:doc => 'foo'}, :safe => nil) ---> NONE = new WriteConcern(-1)
10
+ #@collection.save({:doc => 'foo'}, :safe => true) ---> NORMAL = new WriteConcern(0)
11
+ #@collection.save({:doc => 'foo'}, :safe => {:w => 2}) ---> new WriteConcern( 2 , 0 , false)
12
+ #@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200}) ---> new WriteConcern( 2 , 200 , false)
13
+ #@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :fsync => true}) ---> new WriteConcern( 2 , 0 , true)
14
+ #@collection.save({:doc => 'foo'}, :safe => {:fsync => true}) ---> FSYNC_SAFE = new WriteConcern( 1 , 0 , true)
15
+
16
+ def write_concern(safe)
17
+ return @j_db.write_concern if safe.nil?
18
+ return JMongo::WriteConcern.new(0) if safe.is_a?(FalseClass)
19
+ return JMongo::WriteConcern.new(1) if safe.is_a?(TrueClass)
20
+ return JMongo::WriteConcern.new(0) unless safe.is_a?(Hash)
21
+ w = safe[:w] || 1
22
+ t = safe[:wtimeout] || 0
23
+ f = !!(safe[:fsync] || false)
24
+ JMongo::WriteConcern.new(w, t, f) #dont laugh!
25
+ end
26
+
9
27
  private
10
28
 
11
29
  def exec_command(cmd)
@@ -25,7 +43,6 @@ module Mongo
25
43
  def get_last_error
26
44
  from_dbobject @j_db.get_last_error
27
45
  end
28
-
29
46
  end
30
47
  end
31
48
  end
@@ -62,7 +62,7 @@ module Mongo
62
62
 
63
63
  def from_dbobject obj
64
64
  # for better upstream compatibility make the objects into ruby hash or array
65
-
65
+
66
66
  case obj
67
67
  when Java::ComMongodb::BasicDBObject, Java::ComMongodb::CommandResult
68
68
  h = obj.hashify
@@ -113,24 +113,6 @@ module Mongo
113
113
  end
114
114
  list
115
115
  end
116
-
117
- #@collection.save({:doc => 'foo'}, :safe => nil) ---> NONE = new WriteConcern(-1)
118
- #@collection.save({:doc => 'foo'}, :safe => true) ---> NORMAL = new WriteConcern(0)
119
- #@collection.save({:doc => 'foo'}, :safe => {:w => 2}) ---> new WriteConcern( 2 , 0 , false)
120
- #@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200}) ---> new WriteConcern( 2 , 200 , false)
121
- #@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :fsync => true}) ---> new WriteConcern( 2 , 0 , true)
122
- #@collection.save({:doc => 'foo'}, :safe => {:fsync => true}) ---> FSYNC_SAFE = new WriteConcern( 1 , 0 , true)
123
-
124
- def write_concern(safe)
125
- return JMongo::WriteConcern.new(-1) if safe.nil?
126
- return JMongo::WriteConcern.new(0) if safe.is_a?(FalseClass)
127
- return JMongo::WriteConcern.new(1) if safe.is_a?(TrueClass)
128
- return JMongo::WriteConcern.new(0) unless safe.is_a?(Hash)
129
- w = safe[:w] || 1
130
- t = safe[:wtimeout] || 0
131
- f = !!(safe[:fsync] || false)
132
- JMongo::WriteConcern.new(w, t, f) #dont laugh!
133
- end
134
116
  end
135
117
  end
136
118
  end
@@ -1,3 +1,3 @@
1
1
  module Mongo
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,62 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jmongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ prerelease:
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chuck Remes
9
9
  - Guy Boertje
10
10
  - Lee Henson
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-10-03 00:00:00.000000000 Z
14
+ date: 2011-10-06 00:00:00.000000000 +01:00
15
+ default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: require_all
18
- requirement: &21113940 !ruby/object:Gem::Requirement
19
- none: false
19
+ version_requirements: &2202 !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
23
  version: '1.2'
24
- type: :runtime
24
+ none: false
25
+ requirement: *2202
25
26
  prerelease: false
26
- version_requirements: *21113940
27
+ type: :runtime
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: awesome_print
29
- requirement: &21113180 !ruby/object:Gem::Requirement
30
- none: false
30
+ version_requirements: &2220 !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0.4'
35
- type: :development
35
+ none: false
36
+ requirement: *2220
36
37
  prerelease: false
37
- version_requirements: *21113180
38
+ type: :development
38
39
  - !ruby/object:Gem::Dependency
39
40
  name: fuubar
40
- requirement: &21112600 !ruby/object:Gem::Requirement
41
- none: false
41
+ version_requirements: &2238 !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.0'
46
- type: :development
46
+ none: false
47
+ requirement: *2238
47
48
  prerelease: false
48
- version_requirements: *21112600
49
+ type: :development
49
50
  - !ruby/object:Gem::Dependency
50
51
  name: rspec
51
- requirement: &21112020 !ruby/object:Gem::Requirement
52
- none: false
52
+ version_requirements: &2254 !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ~>
55
55
  - !ruby/object:Gem::Version
56
56
  version: '2.6'
57
- type: :development
57
+ none: false
58
+ requirement: *2254
58
59
  prerelease: false
59
- version_requirements: *21112020
60
+ type: :development
60
61
  description: Thin jruby wrapper around Mongo Java Driver
61
62
  email:
62
63
  - cremes@mac.com
@@ -93,7 +94,6 @@ files:
93
94
  - lib/jmongo/version.rb
94
95
  - spec/jmongo_spec.rb
95
96
  - spec/spec_helper.rb
96
- - test-results.txt
97
97
  - test/auxillary/1.4_features.rb
98
98
  - test/auxillary/authentication_test.rb
99
99
  - test/auxillary/autoreconnect_test.rb
@@ -164,28 +164,30 @@ files:
164
164
  - test/unit/read_test.rb
165
165
  - test/unit/safe_test.rb
166
166
  - test/uri_test.rb
167
+ has_rdoc: true
167
168
  homepage: http://github.com/guyboertje/jmongo
168
169
  licenses: []
169
- post_install_message:
170
+ post_install_message:
170
171
  rdoc_options: []
171
172
  require_paths:
172
173
  - lib
173
174
  required_ruby_version: !ruby/object:Gem::Requirement
174
- none: false
175
175
  requirements:
176
176
  - - ! '>='
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
- required_rubygems_version: !ruby/object:Gem::Requirement
180
179
  none: false
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  requirements:
182
182
  - - ! '>='
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
+ none: false
185
186
  requirements: []
186
- rubyforge_project:
187
- rubygems_version: 1.8.6
188
- signing_key:
187
+ rubyforge_project:
188
+ rubygems_version: 1.5.1
189
+ signing_key:
189
190
  specification_version: 3
190
191
  summary: Thin ruby wrapper around Mongo Java Driver; for JRuby only
191
192
  test_files: []
193
+ ...
@@ -1,98 +0,0 @@
1
- Loaded suite ./test/collection_test
2
- Started
3
- "test_map_reduce_with_raw_response"
4
- "function() { emit(this.user_id, 1); }"
5
- "function(k,vals) { return 1; }"
6
- {
7
- "result" => "foo",
8
- "timeMillis" => 18,
9
- "timing" => {
10
- "mapTime" => 0,
11
- "emitLoop" => 17,
12
- "total" => 18
13
- },
14
- "counts" => {
15
- "input" => 3,
16
- "emit" => 3,
17
- "output" => 3
18
- },
19
- "ok" => 1.0
20
- }
21
- ........."test_map_reduce_with_output_collection"
22
- "function() { emit(this.user_id, 1); }"
23
- "function(k,vals) { return 1; }"
24
- {
25
- "result" => "test-map-coll",
26
- "timeMillis" => 1,
27
- "timing" => {
28
- "mapTime" => 0,
29
- "emitLoop" => 0,
30
- "total" => 1
31
- },
32
- "counts" => {
33
- "input" => 3,
34
- "emit" => 3,
35
- "output" => 3
36
- },
37
- "ok" => 1.0
38
- }
39
- ....."test_map_reduce_with_code_objects"
40
- "function() { emit(this.user_id, 1); }"
41
- "function(k,vals) { return 1; }"
42
- {
43
- "result" => "foo",
44
- "timeMillis" => 1,
45
- "timing" => {
46
- "mapTime" => 0,
47
- "emitLoop" => 0,
48
- "total" => 1
49
- },
50
- "counts" => {
51
- "input" => 2,
52
- "emit" => 2,
53
- "output" => 2
54
- },
55
- "ok" => 1.0
56
- }
57
- ..."test_map_reduce_with_options"
58
- "function() { emit(this.user_id, 1); }"
59
- "function(k,vals) { return 1; }"
60
- {
61
- "result" => "foo",
62
- "timeMillis" => 1,
63
- "timing" => {
64
- "mapTime" => 0,
65
- "emitLoop" => 0,
66
- "total" => 1
67
- },
68
- "counts" => {
69
- "input" => 2,
70
- "emit" => 2,
71
- "output" => 2
72
- },
73
- "ok" => 1.0
74
- }
75
- .."test_map_reduce"
76
- "function() { emit(this.user_id, 1); }"
77
- "function(k,vals) { return 1; }"
78
- {
79
- "result" => "foo",
80
- "timeMillis" => 1,
81
- "timing" => {
82
- "mapTime" => 0,
83
- "emitLoop" => 0,
84
- "total" => 1
85
- },
86
- "counts" => {
87
- "input" => 2,
88
- "emit" => 2,
89
- "output" => 2
90
- },
91
- "ok" => 1.0
92
- }
93
- ..............
94
- Finished in 0.304000 seconds.
95
-
96
- 33 tests, 94 assertions, 0 failures, 0 errors, 0 skips
97
-
98
- Test run options: --seed 45344