jmongo 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +43 -0
- data/Rakefile +72 -0
- data/jmongo.gemspec +84 -6
- data/lib/jmongo.rb +6 -14
- data/lib/jmongo/collection.rb +196 -114
- data/lib/jmongo/connection.rb +39 -13
- data/lib/jmongo/cursor.rb +161 -63
- data/lib/jmongo/db.rb +119 -30
- data/lib/jmongo/exceptions.rb +39 -0
- data/lib/jmongo/mongo-2.6.5.gb1.jar +0 -0
- data/lib/jmongo/mongo/bson.rb +130 -0
- data/lib/jmongo/mongo/collection.rb +185 -0
- data/lib/jmongo/mongo/connection.rb +45 -0
- data/lib/jmongo/mongo/db.rb +31 -0
- data/lib/jmongo/mongo/jmongo.rb +44 -0
- data/lib/jmongo/mongo/mongo.rb +98 -0
- data/lib/jmongo/mongo/ruby_ext.rb +38 -0
- data/lib/jmongo/mongo/utils.rb +136 -0
- data/lib/jmongo/version.rb +1 -1
- data/test-results.txt +98 -0
- data/test/auxillary/1.4_features.rb +166 -0
- data/test/auxillary/authentication_test.rb +68 -0
- data/test/auxillary/autoreconnect_test.rb +41 -0
- data/test/auxillary/fork_test.rb +30 -0
- data/test/auxillary/repl_set_auth_test.rb +58 -0
- data/test/auxillary/slave_connection_test.rb +36 -0
- data/test/auxillary/threaded_authentication_test.rb +101 -0
- data/test/bson/binary_test.rb +15 -0
- data/test/bson/bson_test.rb +657 -0
- data/test/bson/byte_buffer_test.rb +208 -0
- data/test/bson/hash_with_indifferent_access_test.rb +38 -0
- data/test/bson/json_test.rb +17 -0
- data/test/bson/object_id_test.rb +138 -0
- data/test/bson/ordered_hash_test.rb +245 -0
- data/test/bson/test_helper.rb +46 -0
- data/test/bson/timestamp_test.rb +46 -0
- data/test/collection_test.rb +933 -0
- data/test/connection_test.rb +325 -0
- data/test/conversions_test.rb +121 -0
- data/test/cursor_fail_test.rb +75 -0
- data/test/cursor_message_test.rb +43 -0
- data/test/cursor_test.rb +547 -0
- data/test/data/empty_data +0 -0
- data/test/data/sample_data +0 -0
- data/test/data/sample_file.pdf +0 -0
- data/test/data/small_data.txt +1 -0
- data/test/db_api_test.rb +739 -0
- data/test/db_connection_test.rb +15 -0
- data/test/db_test.rb +325 -0
- data/test/grid_file_system_test.rb +260 -0
- data/test/grid_io_test.rb +210 -0
- data/test/grid_test.rb +259 -0
- data/test/load/thin/config.ru +6 -0
- data/test/load/thin/config.yml.template +6 -0
- data/test/load/thin/load.rb +24 -0
- data/test/load/unicorn/config.ru +6 -0
- data/test/load/unicorn/load.rb +23 -0
- data/test/load/unicorn/unicorn.rb.template +29 -0
- data/test/replica_sets/connect_test.rb +111 -0
- data/test/replica_sets/connection_string_test.rb +29 -0
- data/test/replica_sets/count_test.rb +36 -0
- data/test/replica_sets/insert_test.rb +54 -0
- data/test/replica_sets/pooled_insert_test.rb +58 -0
- data/test/replica_sets/query_secondaries.rb +109 -0
- data/test/replica_sets/query_test.rb +52 -0
- data/test/replica_sets/read_preference_test.rb +43 -0
- data/test/replica_sets/refresh_test.rb +123 -0
- data/test/replica_sets/replication_ack_test.rb +71 -0
- data/test/replica_sets/rs_test_helper.rb +27 -0
- data/test/safe_test.rb +68 -0
- data/test/support/hash_with_indifferent_access.rb +186 -0
- data/test/support/keys.rb +45 -0
- data/test/support_test.rb +19 -0
- data/test/test_helper.rb +111 -0
- data/test/threading/threading_with_large_pool_test.rb +90 -0
- data/test/threading_test.rb +88 -0
- data/test/tools/auth_repl_set_manager.rb +14 -0
- data/test/tools/keyfile.txt +1 -0
- data/test/tools/repl_set_manager.rb +377 -0
- data/test/unit/collection_test.rb +128 -0
- data/test/unit/connection_test.rb +85 -0
- data/test/unit/cursor_test.rb +127 -0
- data/test/unit/db_test.rb +96 -0
- data/test/unit/grid_test.rb +51 -0
- data/test/unit/node_test.rb +73 -0
- data/test/unit/pool_manager_test.rb +47 -0
- data/test/unit/pool_test.rb +9 -0
- data/test/unit/read_test.rb +101 -0
- data/test/unit/safe_test.rb +125 -0
- data/test/uri_test.rb +92 -0
- metadata +170 -99
- data/lib/jmongo/ajrb.rb +0 -189
- data/lib/jmongo/jmongo_jext.rb +0 -302
- data/lib/jmongo/mongo-2.6.3.jar +0 -0
- data/lib/jmongo/utils.rb +0 -61
metadata
CHANGED
@@ -1,120 +1,191 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jmongo
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
authors:
|
8
|
+
- Chuck Remes
|
9
|
+
- Guy Boertje
|
10
|
+
- Lee Henson
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
version_requirements: *id004
|
14
|
+
date: 2011-10-03 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: require_all
|
18
|
+
requirement: &21113940 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.2'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *21113940
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: &21113180 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.4'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *21113180
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: fuubar
|
40
|
+
requirement: &21112600 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *21112600
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: &21112020 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.6'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *21112020
|
61
60
|
description: Thin jruby wrapper around Mongo Java Driver
|
62
|
-
email:
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
executables:
|
67
|
-
|
61
|
+
email:
|
62
|
+
- cremes@mac.com
|
63
|
+
- guyboertje@gmail.com
|
64
|
+
- lee.m.henson@gmail.com
|
65
|
+
executables:
|
66
|
+
- jmongo
|
68
67
|
extensions: []
|
69
|
-
|
70
68
|
extra_rdoc_files: []
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
69
|
+
files:
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- History.txt
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.txt
|
75
|
+
- Rakefile
|
76
|
+
- bin/jmongo
|
77
|
+
- jmongo.gemspec
|
78
|
+
- lib/jmongo.rb
|
79
|
+
- lib/jmongo/collection.rb
|
80
|
+
- lib/jmongo/connection.rb
|
81
|
+
- lib/jmongo/cursor.rb
|
82
|
+
- lib/jmongo/db.rb
|
83
|
+
- lib/jmongo/exceptions.rb
|
84
|
+
- lib/jmongo/mongo-2.6.5.gb1.jar
|
85
|
+
- lib/jmongo/mongo/bson.rb
|
86
|
+
- lib/jmongo/mongo/collection.rb
|
87
|
+
- lib/jmongo/mongo/connection.rb
|
88
|
+
- lib/jmongo/mongo/db.rb
|
89
|
+
- lib/jmongo/mongo/jmongo.rb
|
90
|
+
- lib/jmongo/mongo/mongo.rb
|
91
|
+
- lib/jmongo/mongo/ruby_ext.rb
|
92
|
+
- lib/jmongo/mongo/utils.rb
|
93
|
+
- lib/jmongo/version.rb
|
94
|
+
- spec/jmongo_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- test-results.txt
|
97
|
+
- test/auxillary/1.4_features.rb
|
98
|
+
- test/auxillary/authentication_test.rb
|
99
|
+
- test/auxillary/autoreconnect_test.rb
|
100
|
+
- test/auxillary/fork_test.rb
|
101
|
+
- test/auxillary/repl_set_auth_test.rb
|
102
|
+
- test/auxillary/slave_connection_test.rb
|
103
|
+
- test/auxillary/threaded_authentication_test.rb
|
104
|
+
- test/bson/binary_test.rb
|
105
|
+
- test/bson/bson_test.rb
|
106
|
+
- test/bson/byte_buffer_test.rb
|
107
|
+
- test/bson/hash_with_indifferent_access_test.rb
|
108
|
+
- test/bson/json_test.rb
|
109
|
+
- test/bson/object_id_test.rb
|
110
|
+
- test/bson/ordered_hash_test.rb
|
111
|
+
- test/bson/test_helper.rb
|
112
|
+
- test/bson/timestamp_test.rb
|
113
|
+
- test/collection_test.rb
|
114
|
+
- test/connection_test.rb
|
115
|
+
- test/conversions_test.rb
|
116
|
+
- test/cursor_fail_test.rb
|
117
|
+
- test/cursor_message_test.rb
|
118
|
+
- test/cursor_test.rb
|
119
|
+
- test/data/empty_data
|
120
|
+
- test/data/sample_data
|
121
|
+
- test/data/sample_file.pdf
|
122
|
+
- test/data/small_data.txt
|
123
|
+
- test/db_api_test.rb
|
124
|
+
- test/db_connection_test.rb
|
125
|
+
- test/db_test.rb
|
126
|
+
- test/grid_file_system_test.rb
|
127
|
+
- test/grid_io_test.rb
|
128
|
+
- test/grid_test.rb
|
129
|
+
- test/load/thin/config.ru
|
130
|
+
- test/load/thin/config.yml.template
|
131
|
+
- test/load/thin/load.rb
|
132
|
+
- test/load/unicorn/config.ru
|
133
|
+
- test/load/unicorn/load.rb
|
134
|
+
- test/load/unicorn/unicorn.rb.template
|
135
|
+
- test/replica_sets/connect_test.rb
|
136
|
+
- test/replica_sets/connection_string_test.rb
|
137
|
+
- test/replica_sets/count_test.rb
|
138
|
+
- test/replica_sets/insert_test.rb
|
139
|
+
- test/replica_sets/pooled_insert_test.rb
|
140
|
+
- test/replica_sets/query_secondaries.rb
|
141
|
+
- test/replica_sets/query_test.rb
|
142
|
+
- test/replica_sets/read_preference_test.rb
|
143
|
+
- test/replica_sets/refresh_test.rb
|
144
|
+
- test/replica_sets/replication_ack_test.rb
|
145
|
+
- test/replica_sets/rs_test_helper.rb
|
146
|
+
- test/safe_test.rb
|
147
|
+
- test/support/hash_with_indifferent_access.rb
|
148
|
+
- test/support/keys.rb
|
149
|
+
- test/support_test.rb
|
150
|
+
- test/test_helper.rb
|
151
|
+
- test/threading/threading_with_large_pool_test.rb
|
152
|
+
- test/threading_test.rb
|
153
|
+
- test/tools/auth_repl_set_manager.rb
|
154
|
+
- test/tools/keyfile.txt
|
155
|
+
- test/tools/repl_set_manager.rb
|
156
|
+
- test/unit/collection_test.rb
|
157
|
+
- test/unit/connection_test.rb
|
158
|
+
- test/unit/cursor_test.rb
|
159
|
+
- test/unit/db_test.rb
|
160
|
+
- test/unit/grid_test.rb
|
161
|
+
- test/unit/node_test.rb
|
162
|
+
- test/unit/pool_manager_test.rb
|
163
|
+
- test/unit/pool_test.rb
|
164
|
+
- test/unit/read_test.rb
|
165
|
+
- test/unit/safe_test.rb
|
166
|
+
- test/uri_test.rb
|
92
167
|
homepage: http://github.com/guyboertje/jmongo
|
93
168
|
licenses: []
|
94
|
-
|
95
169
|
post_install_message:
|
96
170
|
rdoc_options: []
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
174
|
none: false
|
102
|
-
requirements:
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ! '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
180
|
none: false
|
108
|
-
requirements:
|
109
|
-
|
110
|
-
|
111
|
-
|
181
|
+
requirements:
|
182
|
+
- - ! '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
112
185
|
requirements: []
|
113
|
-
|
114
186
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.8.
|
187
|
+
rubygems_version: 1.8.6
|
116
188
|
signing_key:
|
117
189
|
specification_version: 3
|
118
190
|
summary: Thin ruby wrapper around Mongo Java Driver; for JRuby only
|
119
191
|
test_files: []
|
120
|
-
|
data/lib/jmongo/ajrb.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 Guy Boertje
|
2
|
-
#
|
3
|
-
# Mongo::JavaImpl::Connection_
|
4
|
-
# Mongo::JavaImpl::Db_
|
5
|
-
# Mongo::JavaImpl::Collection_
|
6
|
-
# Mongo::JavaImpl::Utils
|
7
|
-
#
|
8
|
-
|
9
|
-
module Mongo
|
10
|
-
|
11
|
-
module JavaImpl
|
12
|
-
|
13
|
-
module Connection_
|
14
|
-
module InstanceMethods
|
15
|
-
private
|
16
|
-
def get_db_names
|
17
|
-
@connection.get_database_names
|
18
|
-
end
|
19
|
-
def drop_a_db name
|
20
|
-
@connection.drop_database(name)
|
21
|
-
end
|
22
|
-
def _server_version
|
23
|
-
@connection.get_version
|
24
|
-
end
|
25
|
-
end
|
26
|
-
module ClassMethods
|
27
|
-
URI_RE = /^mongodb:\/\/(([-.\w]+):([^@]+)@)?([-.\w]+)(:([\w]+))?(\/([-\w]+))?/
|
28
|
-
OPTS_KEYS = %W[maxpoolsize waitqueuemultiple waitqueuetimeoutms connecttimeoutms sockettimeoutms
|
29
|
-
autoconnectretry slaveok safe w wtimeout fsync]
|
30
|
-
|
31
|
-
def _from_uri uri, opts={}
|
32
|
-
optarr = []
|
33
|
-
unless uri =~ URI_RE
|
34
|
-
raise MongoArgumentError, "MongoDB URI incorrect"
|
35
|
-
end
|
36
|
-
pieces = uri.split("//")
|
37
|
-
extra = pieces.last.count('/') == 0 ? "/" : ""
|
38
|
-
opts.each do|k,v|
|
39
|
-
if OPTS_KEYS.include?(k.to_s) && !v.nil?
|
40
|
-
(optarr << "#{k}=#{v}")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
unless optarr.empty?
|
44
|
-
uri << "#{extra}?" << optarr.join("&")
|
45
|
-
end
|
46
|
-
puts "+++++++++++++++ _from_uri uri: #{uri.inspect}"
|
47
|
-
muri = Java::ComMongodb::MongoURI.new(uri)
|
48
|
-
opts[:new_from_uri] = JMongo::Mongo.new(muri)
|
49
|
-
new("",0,opts)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
module Db_
|
55
|
-
SYSTEM_NAMESPACE_COLLECTION = "system.namespaces"
|
56
|
-
#SYSTEM_INDEX_COLLECTION = "system.indexes"
|
57
|
-
#SYSTEM_PROFILE_COLLECTION = "system.profile"
|
58
|
-
#SYSTEM_USER_COLLECTION = "system.users"
|
59
|
-
#SYSTEM_COMMAND_COLLECTION = "$cmd"
|
60
|
-
|
61
|
-
private
|
62
|
-
def exec_command(cmd)
|
63
|
-
cmd_res = @j_db.command(to_dbobject({cmd => true}))
|
64
|
-
from_dbobject(cmd_res)
|
65
|
-
end
|
66
|
-
def has_coll(name)
|
67
|
-
@j_db.collection_exists(name)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module Collection_
|
72
|
-
private
|
73
|
-
def create_indexes(obj,opts)
|
74
|
-
return @j_collection.ensureIndex("#{obj}") if obj.is_a?(String) || obj.is_a?(Symbol)
|
75
|
-
|
76
|
-
obj = Hash[obj] if obj.is_a?(Array)
|
77
|
-
|
78
|
-
return @j_collection.ensureIndex(to_dbobject(obj),to_dbobject(opts)) if opts.is_a?(Hash)
|
79
|
-
@j_collection.ensureIndex(to_dbobject(obj),generate_index_name(obj),!!(opts))
|
80
|
-
end
|
81
|
-
|
82
|
-
def remove_documents(obj, safe=nil)
|
83
|
-
wr = @j_collection.remove(to_dbobject(obj), write_concern(safe))
|
84
|
-
wr.get_error.nil? && wr.get_n > 0
|
85
|
-
end
|
86
|
-
|
87
|
-
def insert_documents(obj, safe=nil)
|
88
|
-
dbo = to_dbobject(obj)
|
89
|
-
@j_collection.insert(dbo, write_concern(safe))
|
90
|
-
obj.collect { |o| o['_id'] || o[:_id] }
|
91
|
-
end
|
92
|
-
|
93
|
-
def find_and_modify_document(query,fields,sort,remove,update,new_,upsert)
|
94
|
-
from_dbobject @j_collection.find_and_modify(to_dbobject(query),to_dbobject(fields),to_dbobject(sort),remove,to_dbobject(update),new_,upsert)
|
95
|
-
end
|
96
|
-
|
97
|
-
def find_one_document(document, fields)
|
98
|
-
from_dbobject @j_collection.findOne(to_dbobject(document),to_dbobject(fields))
|
99
|
-
end
|
100
|
-
|
101
|
-
def update_documents(selector, document, upsert=false, multi=false, safe=nil)
|
102
|
-
@j_collection.update(to_dbobject(selector),to_dbobject(document), upsert, multi, write_concern(safe))
|
103
|
-
end
|
104
|
-
|
105
|
-
def save_document(obj, safe=nil)
|
106
|
-
id = obj.delete(:_id) || obj.delete('_id')
|
107
|
-
obj['_id'] = id || BSON::ObjectId.new
|
108
|
-
db_obj = to_dbobject(obj)
|
109
|
-
@j_collection.save(db_obj, write_concern(safe))
|
110
|
-
obj['_id']
|
111
|
-
end
|
112
|
-
end
|
113
|
-
module NoImplYetClass
|
114
|
-
def raise_not_implemented
|
115
|
-
raise NoMethodError, "This method hasn't been implemented yet."
|
116
|
-
end
|
117
|
-
end
|
118
|
-
module Utils
|
119
|
-
def raise_not_implemented
|
120
|
-
raise NoMethodError, "This method hasn't been implemented yet."
|
121
|
-
end
|
122
|
-
|
123
|
-
def to_dbobject obj
|
124
|
-
if obj.respond_to?(:merge)
|
125
|
-
hash_to_dbobject(obj)
|
126
|
-
elsif obj.respond_to?(:compact)
|
127
|
-
array_to_dblist(obj)
|
128
|
-
elsif obj.class == Symbol
|
129
|
-
obj.to_s
|
130
|
-
else
|
131
|
-
# primitive value, no conversion necessary
|
132
|
-
#puts "Un-handled class type [#{obj.class}]"
|
133
|
-
obj
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def from_dbobject obj
|
138
|
-
# for better upstream compatibility make the objects into ruby hash or array
|
139
|
-
if obj.class == Java::ComMongodb::BasicDBObject
|
140
|
-
h = obj.hashify
|
141
|
-
Hash[h.keys.zip(h.values.map{|v| from_dbobject(v)})]
|
142
|
-
elsif obj.class == Java::ComMongodb::BasicDBList
|
143
|
-
obj.arrayify.map{|v| from_dbobject(v)}
|
144
|
-
elsif obj.class == Java::JavaUtil::Date
|
145
|
-
Time.at(obj.get_time/1000.0)
|
146
|
-
else
|
147
|
-
obj
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
private
|
152
|
-
|
153
|
-
def hash_to_dbobject doc
|
154
|
-
obj = JMongo::BasicDBObject.new
|
155
|
-
doc.each_pair do |key, value|
|
156
|
-
obj.put(key.to_s, to_dbobject(value))
|
157
|
-
end
|
158
|
-
obj
|
159
|
-
end
|
160
|
-
|
161
|
-
def array_to_dblist ary
|
162
|
-
list = [] #Java::ComMongodb::DBObject[ary.length].new
|
163
|
-
ary.each_with_index do |ele, i|
|
164
|
-
list[i] = to_dbobject(ele)
|
165
|
-
end
|
166
|
-
list
|
167
|
-
end
|
168
|
-
|
169
|
-
#@collection.save({:doc => 'foo'}, :safe => nil) ---> NONE = new WriteConcern(-1)
|
170
|
-
#@collection.save({:doc => 'foo'}, :safe => true) ---> NORMAL = new WriteConcern(0)
|
171
|
-
#@collection.save({:doc => 'foo'}, :safe => {:w => 2}) ---> new WriteConcern( 2 , 0 , false)
|
172
|
-
#@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200}) ---> new WriteConcern( 2 , 200 , false)
|
173
|
-
#@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :fsync => true}) ---> new WriteConcern( 2 , 0 , true)
|
174
|
-
#@collection.save({:doc => 'foo'}, :safe => {:fsync => true}) ---> FSYNC_SAFE = new WriteConcern( 1 , 0 , true)
|
175
|
-
|
176
|
-
def write_concern(safe)
|
177
|
-
return JMongo::WriteConcern.new(-1) if safe.nil?
|
178
|
-
return JMongo::WriteConcern.new(0) if safe.is_a?(FalseClass)
|
179
|
-
return JMongo::WriteConcern.new(1) if safe.is_a?(TrueClass)
|
180
|
-
return JMongo::WriteConcern.new(0) unless safe.is_a?(Hash)
|
181
|
-
w = safe[:w] || 1
|
182
|
-
t = safe[:wtimeout] || 0
|
183
|
-
f = !!(safe[:fsync] || false)
|
184
|
-
JMongo::WriteConcern.new(w, t, f) #dont laugh!
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|