mongo 2.0.0.rc → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -1
- data/README.md +1 -4
- data/lib/mongo/client.rb +1 -1
- data/lib/mongo/collection.rb +1 -1
- data/lib/mongo/collection/view.rb +1 -1
- data/lib/mongo/collection/view/writable.rb +26 -10
- data/lib/mongo/database.rb +1 -1
- data/lib/mongo/grid/file.rb +12 -0
- data/lib/mongo/grid/file/chunk.rb +1 -1
- data/lib/mongo/grid/file/metadata.rb +13 -0
- data/lib/mongo/operation/aggregate.rb +1 -1
- data/lib/mongo/operation/write.rb +1 -5
- data/lib/mongo/operation/write/bulk.rb +17 -0
- data/lib/mongo/operation/write/{bulk_delete.rb → bulk/bulk_delete.rb} +1 -1
- data/lib/mongo/operation/{bulk_delete → write/bulk/bulk_delete}/result.rb +3 -0
- data/lib/mongo/operation/write/{bulk_insert.rb → bulk/bulk_insert.rb} +1 -1
- data/lib/mongo/operation/{bulk_insert → write/bulk/bulk_insert}/result.rb +3 -0
- data/lib/mongo/operation/write/{bulk_mergable.rb → bulk/bulk_mergable.rb} +0 -0
- data/lib/mongo/operation/write/{bulk_update.rb → bulk/bulk_update.rb} +1 -1
- data/lib/mongo/operation/{bulk_update → write/bulk/bulk_update}/result.rb +8 -1
- data/lib/mongo/operation/write/{legacy_bulk_mergable.rb → bulk/legacy_bulk_mergable.rb} +0 -0
- data/lib/mongo/operation/write/delete.rb +2 -0
- data/lib/mongo/operation/write/delete/result.rb +40 -0
- data/lib/mongo/operation/write/insert.rb +2 -0
- data/lib/mongo/operation/write/insert/result.rb +32 -0
- data/lib/mongo/operation/write/update.rb +9 -4
- data/lib/mongo/operation/write/update/result.rb +160 -0
- data/lib/mongo/server/connectable.rb +11 -0
- data/lib/mongo/server/connection.rb +1 -0
- data/lib/mongo/server/connection_pool.rb +1 -1
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/monitor.rb +16 -0
- data/lib/mongo/server/monitor/connection.rb +1 -0
- data/lib/mongo/socket/ssl.rb +30 -8
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +1 -1
- data/lib/mongo/write_concern/unacknowledged.rb +1 -1
- data/spec/certificates/ca.pem +17 -0
- data/spec/certificates/client.pem +101 -0
- data/spec/certificates/crl.pem +10 -0
- data/spec/certificates/crl_client_revoked.pem +12 -0
- data/spec/certificates/password_protected.pem +51 -0
- data/spec/certificates/server.pem +34 -0
- data/spec/mongo/collection/view/writable_spec.rb +175 -0
- data/spec/mongo/crud_spec.rb +42 -0
- data/spec/mongo/grid/file/metadata_spec.rb +23 -0
- data/spec/mongo/grid/file_spec.rb +34 -0
- data/spec/mongo/operation/write/delete_spec.rb +8 -0
- data/spec/mongo/operation/write/insert_spec.rb +21 -8
- data/spec/mongo/operation/write/update_spec.rb +52 -1
- data/spec/mongo/server/connection_spec.rb +33 -10
- data/spec/mongo/server/monitor_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -17
- data/spec/support/crud.rb +203 -0
- data/spec/support/crud/read.rb +144 -0
- data/spec/support/crud/write.rb +214 -0
- data/spec/support/crud_tests/read/aggregate.yml +43 -0
- data/spec/support/crud_tests/read/count.yml +37 -0
- data/spec/support/crud_tests/read/distinct.yml +33 -0
- data/spec/support/crud_tests/read/find.yml +50 -0
- data/spec/support/crud_tests/write/deleteMany.yml +36 -0
- data/spec/support/crud_tests/write/deleteOne.yml +49 -0
- data/spec/support/crud_tests/write/findOneAndDelete.yml +54 -0
- data/spec/support/crud_tests/write/findOneAndReplace.yml +153 -0
- data/spec/support/crud_tests/write/findOneAndUpdate.yml +161 -0
- data/spec/support/crud_tests/write/insertMany.yml +24 -0
- data/spec/support/crud_tests/write/insertOne.yml +19 -0
- data/spec/support/crud_tests/write/replaceOne.yml +96 -0
- data/spec/support/crud_tests/write/updateMany.yml +83 -0
- data/spec/support/crud_tests/write/updateOne.yml +80 -0
- metadata +64 -20
- metadata.gz.sig +0 -0
- data/spec/mongo_orchestration_spec.rb +0 -70
- data/spec/support/mongo_orchestration.rb +0 -61
- data/spec/support/mongo_orchestration/requestable.rb +0 -109
- data/spec/support/mongo_orchestration/standalone.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1b1c17b52cc160be41aa083e33789a71d99b6b8
|
4
|
+
data.tar.gz: ba505d3b59d858a210a570670a98c6baded60489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e770b0aee96c3226681ae96fb0de826fbb4c10ddb8851bd4d9ce763b0cd6d8c1067ec50f42748d84ac31e1ca009e641d2f7f66e780166a8cd4adc33e9db6183
|
7
|
+
data.tar.gz: 5a34d970f35bcd33d06dbfc61ae533cd05a5f585bb242d9e591805d3545902d2cfd74071587bbd47f997318ad9012012c3ad4d951ca0f79ce9c5488324d890cf
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
�W^�}�*�m��`�q��_�cN�m(1=pz�,1G����|EE!�� �L�xU��G�uŝ$6H���uVZC��m�_;����@/���R$����o�caU>�z���jB@[�d@��Wt��?J;��k/{�B$�k(���:�pZ�K��PC�Dz��X;[� �e�<뤩=�����J��Zf��j�՝��<��;�Fx���j$v�U
|
2
|
+
��k��r;��b|����?���
|
data/README.md
CHANGED
@@ -2,13 +2,10 @@ MongoDB Ruby Driver [![Build Status][travis-img]][travis-url] [![Code Climate][c
|
|
2
2
|
-----
|
3
3
|
The officially supported Ruby driver for [MongoDB](http://www.mongodb.org).
|
4
4
|
|
5
|
-
> **Note: You are viewing the 2.x version of the MongoDB Ruby driver which is currently in beta and under heavy development. To view the current stable version of driver, please use the [1.x-stable](https://github.com/mongodb/mongo-ruby-driver/tree/1.x-stable) branch.**
|
6
|
-
|
7
5
|
Documentation
|
8
6
|
-----
|
9
7
|
|
10
|
-
Documentation
|
11
|
-
be seen in the meantime [here](https://github.com/durran/docs-ecosystem/blob/RUBY-684/source/tutorial/ruby-driver-tutorial.txt).
|
8
|
+
Documentation is located [here](http://docs.mongodb.org/ecosystem/drivers/ruby/).
|
12
9
|
|
13
10
|
API docs can be found [here](http://api.mongodb.org/ruby/).
|
14
11
|
|
data/lib/mongo/client.rb
CHANGED
@@ -154,7 +154,7 @@ module Mongo
|
|
154
154
|
#
|
155
155
|
# @since 2.0.0
|
156
156
|
def inspect
|
157
|
-
"
|
157
|
+
"#<Mongo::Client:0x#{object_id} cluster=#{cluster.addresses.join(', ')}>"
|
158
158
|
end
|
159
159
|
|
160
160
|
# Get the read preference from the options passed to the client.
|
data/lib/mongo/collection.rb
CHANGED
@@ -139,7 +139,7 @@ module Mongo
|
|
139
139
|
#
|
140
140
|
# @since 2.0.0
|
141
141
|
def inspect
|
142
|
-
"
|
142
|
+
"#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}" +
|
143
143
|
" @selector=#{selector.inspect} @options=#{options.inspect}>"
|
144
144
|
end
|
145
145
|
|
@@ -77,9 +77,10 @@ module Mongo
|
|
77
77
|
cmd[:update] = document
|
78
78
|
cmd[:fields] = projection if projection
|
79
79
|
cmd[:sort] = sort if sort
|
80
|
-
cmd[:new] = (opts[:return_document]
|
80
|
+
cmd[:new] = !!(opts[:return_document] && opts[:return_document] == :after)
|
81
81
|
cmd[:upsert] = opts[:upsert] if opts[:upsert]
|
82
|
-
database.command(cmd).first['value']
|
82
|
+
value = database.command(cmd).first['value']
|
83
|
+
value unless value.nil? || value.empty?
|
83
84
|
end
|
84
85
|
|
85
86
|
# Remove documents from the collection.
|
@@ -112,36 +113,48 @@ module Mongo
|
|
112
113
|
# collection_view.replace_one({ name: 'test' })
|
113
114
|
#
|
114
115
|
# @param [ Hash ] document The document to replace.
|
116
|
+
# @param [ Hash ] opts The options.
|
117
|
+
#
|
118
|
+
# @option opts [ true, false ] :upsert Whether to upsert if the
|
119
|
+
# document doesn't exist.
|
115
120
|
#
|
116
121
|
# @return [ Result ] The response from the database.
|
117
122
|
#
|
118
123
|
# @since 2.0.0
|
119
|
-
def replace_one(document)
|
120
|
-
update(document, false)
|
124
|
+
def replace_one(document, opts = {})
|
125
|
+
update(document, false, opts)
|
121
126
|
end
|
122
127
|
|
123
128
|
# Update documents in the collection.
|
124
129
|
#
|
125
130
|
# @example Update multiple documents in the collection.
|
126
131
|
# collection_view.update_many('$set' => { name: 'test' })
|
132
|
+
# @param [ Hash ] opts The options.
|
133
|
+
#
|
134
|
+
# @option opts [ true, false ] :upsert Whether to upsert if the
|
135
|
+
# document doesn't exist.
|
127
136
|
#
|
128
137
|
# @return [ Result ] The response from the database.
|
129
138
|
#
|
130
139
|
# @since 2.0.0
|
131
|
-
def update_many(spec)
|
132
|
-
update(spec, true)
|
140
|
+
def update_many(spec, opts = {})
|
141
|
+
update(spec, true, opts)
|
133
142
|
end
|
134
143
|
|
135
144
|
# Update a single document in the collection.
|
136
145
|
#
|
137
146
|
# @example Update a single document in the collection.
|
138
147
|
# collection_view.update_one('$set' => { name: 'test' })
|
148
|
+
# @param [ Hash ] opts The options.
|
149
|
+
#
|
150
|
+
# @option opts [ true, false ] :upsert Whether to upsert if the
|
151
|
+
# document doesn't exist.
|
139
152
|
#
|
140
153
|
# @return [ Result ] The response from the database.
|
141
154
|
#
|
142
155
|
# @since 2.0.0
|
143
|
-
def update_one(spec)
|
144
|
-
update(spec, false)
|
156
|
+
def update_one(spec, opts = {})
|
157
|
+
update(spec, false, opts)
|
145
158
|
end
|
146
159
|
|
147
160
|
private
|
@@ -155,9 +168,12 @@ module Mongo
|
|
155
168
|
).execute(next_primary.context)
|
156
169
|
end
|
157
170
|
|
158
|
-
def update(spec, multi)
|
171
|
+
def update(spec, multi, opts)
|
159
172
|
Operation::Write::Update.new(
|
160
|
-
:update => { q: selector,
|
173
|
+
:update => { q: selector,
|
174
|
+
u: spec,
|
175
|
+
multi: multi,
|
176
|
+
upsert: !!opts[:upsert] },
|
161
177
|
:db_name => collection.database.name,
|
162
178
|
:coll_name => collection.name,
|
163
179
|
:write_concern => collection.write_concern
|
data/lib/mongo/database.rb
CHANGED
data/lib/mongo/grid/file.rb
CHANGED
@@ -72,6 +72,18 @@ module Mongo
|
|
72
72
|
initialize_chunks!(data)
|
73
73
|
end
|
74
74
|
|
75
|
+
# Gets a pretty inspection of the file.
|
76
|
+
#
|
77
|
+
# @example Get the file inspection.
|
78
|
+
# file.inspect
|
79
|
+
#
|
80
|
+
# @return [ String ] The file inspection.
|
81
|
+
#
|
82
|
+
# @since 2.0.0
|
83
|
+
def inspect
|
84
|
+
"#<Mongo::Grid::File:0x#{object_id} filename=#{filename}>"
|
85
|
+
end
|
86
|
+
|
75
87
|
private
|
76
88
|
|
77
89
|
# @note If we have provided an array of BSON::Documents to initialize
|
@@ -168,7 +168,7 @@ module Mongo
|
|
168
168
|
def split(data, metadata)
|
169
169
|
chunks, index, n = [], 0, 0
|
170
170
|
while index < data.length
|
171
|
-
bytes = data.slice(index,
|
171
|
+
bytes = data.slice(index, metadata.chunk_size)
|
172
172
|
metadata.md5.update(bytes)
|
173
173
|
chunk = Chunk.new(:data => BSON::Binary.new(bytes), :files_id => metadata.id, :n => n)
|
174
174
|
chunks.push(chunk)
|
@@ -133,6 +133,19 @@ module Mongo
|
|
133
133
|
@client_md5 = Digest::MD5.new
|
134
134
|
end
|
135
135
|
|
136
|
+
# Get a readable inspection for the object.
|
137
|
+
#
|
138
|
+
# @example Inspect the metadata.
|
139
|
+
# metadata.inspect
|
140
|
+
#
|
141
|
+
# @return [ String ] The nice inspection.
|
142
|
+
#
|
143
|
+
# @since 2.0.0
|
144
|
+
def inspect
|
145
|
+
"#<Mongo::Grid::File::Metadata:0x#{object_id} chunk_size=#{chunk_size} " +
|
146
|
+
"filename=#{filename} content_type=#{content_type} id=#{id} md5=#{md5}>"
|
147
|
+
end
|
148
|
+
|
136
149
|
# Get the length of the document in bytes.
|
137
150
|
#
|
138
151
|
# @example Get the length
|
@@ -62,7 +62,7 @@ module Mongo
|
|
62
62
|
#
|
63
63
|
# @since 2.0.0
|
64
64
|
def execute(context)
|
65
|
-
unless context.standalone? || context.primary? || secondary_ok?
|
65
|
+
unless context.standalone? || context.mongos? || context.primary? || secondary_ok?
|
66
66
|
raise Error::NeedPrimaryServer.new(ERROR_MESSAGE)
|
67
67
|
end
|
68
68
|
execute_message(context)
|
@@ -12,14 +12,10 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'mongo/operation/write/
|
16
|
-
require 'mongo/operation/write/legacy_bulk_mergable'
|
15
|
+
require 'mongo/operation/write/bulk'
|
17
16
|
require 'mongo/operation/write/delete'
|
18
|
-
require 'mongo/operation/write/bulk_delete'
|
19
17
|
require 'mongo/operation/write/insert'
|
20
|
-
require 'mongo/operation/write/bulk_insert'
|
21
18
|
require 'mongo/operation/write/update'
|
22
|
-
require 'mongo/operation/write/bulk_update'
|
23
19
|
require 'mongo/operation/write/create_index'
|
24
20
|
require 'mongo/operation/write/drop_index'
|
25
21
|
require 'mongo/operation/write/create_user'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright (C) 2014-2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo/operation/write/bulk/bulk_delete'
|
16
|
+
require 'mongo/operation/write/bulk/bulk_insert'
|
17
|
+
require 'mongo/operation/write/bulk/bulk_update'
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'mongo/operation/write/bulk/bulk_mergable'
|
16
|
+
require 'mongo/operation/write/bulk/legacy_bulk_mergable'
|
17
|
+
|
15
18
|
module Mongo
|
16
19
|
module Operation
|
17
20
|
module Write
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'mongo/operation/write/bulk/bulk_mergable'
|
16
|
+
require 'mongo/operation/write/bulk/legacy_bulk_mergable'
|
17
|
+
|
15
18
|
module Mongo
|
16
19
|
module Operation
|
17
20
|
module Write
|
File without changes
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'mongo/operation/write/bulk/bulk_mergable'
|
16
|
+
require 'mongo/operation/write/bulk/legacy_bulk_mergable'
|
17
|
+
|
15
18
|
module Mongo
|
16
19
|
module Operation
|
17
20
|
module Write
|
@@ -146,7 +149,11 @@ module Mongo
|
|
146
149
|
private
|
147
150
|
|
148
151
|
def upsert?(reply)
|
149
|
-
!reply.documents.first[
|
152
|
+
!updated_existing?(reply) && reply.documents.first[N] == 1
|
153
|
+
end
|
154
|
+
|
155
|
+
def updated_existing?(reply)
|
156
|
+
reply.documents.first[UPDATED_EXISTING]
|
150
157
|
end
|
151
158
|
end
|
152
159
|
end
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (C) 2014-2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
module Write
|
18
|
+
class Delete
|
19
|
+
|
20
|
+
# Defines custom behaviour of results for a delete.
|
21
|
+
#
|
22
|
+
# @since 2.0.0
|
23
|
+
class Result < Operation::Result
|
24
|
+
|
25
|
+
# Get the number of documents deleted.
|
26
|
+
#
|
27
|
+
# @example Get the deleted count.
|
28
|
+
# result.deleted_count
|
29
|
+
#
|
30
|
+
# @return [ Integer ] The deleted count.
|
31
|
+
#
|
32
|
+
# @since 2.0.0
|
33
|
+
def deleted_count
|
34
|
+
n
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (C) 2014-2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
module Write
|
18
|
+
class Insert
|
19
|
+
|
20
|
+
# Defines custom behaviour of results for an insert.
|
21
|
+
#
|
22
|
+
# According to the CRUD spec, reporting the inserted ids
|
23
|
+
# is optional. It can be added to this class later, if needed.
|
24
|
+
#
|
25
|
+
# @since 2.0.0
|
26
|
+
class Result < Operation::Result
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'mongo/operation/write/update/result'
|
16
|
+
|
15
17
|
module Mongo
|
16
18
|
module Operation
|
17
19
|
module Write
|
@@ -79,7 +81,7 @@ module Mongo
|
|
79
81
|
|
80
82
|
def execute_message(context)
|
81
83
|
context.with_connection do |connection|
|
82
|
-
|
84
|
+
LegacyResult.new(connection.dispatch([ message, gle ].compact)).validate!
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
@@ -88,9 +90,12 @@ module Mongo
|
|
88
90
|
@spec[:updates] = original.spec[:updates].dup
|
89
91
|
end
|
90
92
|
|
91
|
-
def message
|
92
|
-
|
93
|
-
|
93
|
+
def message
|
94
|
+
flags = []
|
95
|
+
flags << :multi_update if update[:multi]
|
96
|
+
flags << :upsert if update[:upsert]
|
97
|
+
Protocol::Update.new(db_name, coll_name, update[:q], update[:u],
|
98
|
+
flags.empty? ? {} : { flags: flags })
|
94
99
|
end
|
95
100
|
end
|
96
101
|
end
|