mongo 1.8.6 → 1.12.5
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +114 -282
- data/Rakefile +18 -4
- data/VERSION +1 -1
- data/bin/mongo_console +27 -5
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +283 -222
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/{util → connection}/node.rb +58 -6
- data/lib/mongo/{util → connection}/pool.rb +61 -37
- data/lib/mongo/{util → connection}/pool_manager.rb +72 -22
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +13 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/cursor.rb +183 -57
- data/lib/mongo/db.rb +302 -138
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/{util → functional}/logging.rb +23 -7
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/{util → functional}/write_concern.rb +21 -9
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +19 -8
- data/lib/mongo/gridfs/grid_ext.rb +14 -0
- data/lib/mongo/gridfs/grid_file_system.rb +17 -4
- data/lib/mongo/gridfs/grid_io.rb +21 -9
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +76 -7
- data/lib/mongo/mongo_client.rb +246 -206
- data/lib/mongo/mongo_replica_set_client.rb +65 -15
- data/lib/mongo/mongo_sharded_client.rb +18 -3
- data/lib/mongo/networking.rb +47 -18
- data/lib/mongo/{util → utils}/conversions.rb +18 -3
- data/lib/mongo/{util → utils}/core_ext.rb +15 -32
- data/lib/mongo/{util → utils}/server_version.rb +15 -0
- data/lib/mongo/{util → utils}/support.rb +22 -55
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +44 -26
- data/mongo.gemspec +2 -2
- data/test/functional/authentication_test.rb +31 -10
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +1419 -654
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +46 -2
- data/test/functional/cursor_fail_test.rb +17 -9
- data/test/functional/cursor_message_test.rb +28 -15
- data/test/functional/cursor_test.rb +300 -165
- data/test/functional/db_api_test.rb +294 -264
- data/test/functional/db_connection_test.rb +15 -3
- data/test/functional/db_test.rb +165 -99
- data/test/functional/grid_file_system_test.rb +124 -112
- data/test/functional/grid_io_test.rb +17 -3
- data/test/functional/grid_test.rb +16 -2
- data/test/functional/pool_test.rb +99 -10
- data/test/functional/safe_test.rb +18 -4
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +14 -0
- data/test/functional/timeout_test.rb +27 -27
- data/test/functional/uri_test.rb +268 -22
- data/test/functional/write_concern_test.rb +19 -5
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +28 -11
- data/test/replica_set/basic_test.rb +79 -23
- data/test/replica_set/client_test.rb +253 -124
- data/test/replica_set/connection_test.rb +59 -37
- data/test/replica_set/count_test.rb +18 -2
- data/test/replica_set/cursor_test.rb +30 -8
- data/test/replica_set/insert_test.rb +109 -2
- data/test/replica_set/max_values_test.rb +85 -10
- data/test/replica_set/pinning_test.rb +66 -2
- data/test/replica_set/query_test.rb +17 -3
- data/test/replica_set/read_preference_test.rb +115 -96
- data/test/replica_set/refresh_test.rb +59 -9
- data/test/replica_set/replication_ack_test.rb +32 -11
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +73 -25
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +47 -196
- data/test/threading/basic_test.rb +42 -2
- data/test/tools/mongo_config.rb +175 -35
- data/test/tools/mongo_config_test.rb +15 -1
- data/test/unit/client_test.rb +186 -57
- data/test/unit/collection_test.rb +44 -54
- data/test/unit/connection_test.rb +160 -71
- data/test/unit/cursor_test.rb +37 -3
- data/test/unit/db_test.rb +38 -14
- data/test/unit/grid_test.rb +15 -1
- data/test/unit/mongo_sharded_client_test.rb +30 -14
- data/test/unit/node_test.rb +16 -1
- data/test/unit/pool_manager_test.rb +21 -4
- data/test/unit/read_pref_test.rb +386 -1
- data/test/unit/read_test.rb +27 -13
- data/test/unit/safe_test.rb +22 -8
- data/test/unit/sharding_pool_manager_test.rb +25 -4
- data/test/unit/write_concern_test.rb +23 -9
- data.tar.gz.sig +0 -0
- metadata +80 -54
- metadata.gz.sig +0 -0
- data/lib/mongo/exceptions.rb +0 -65
- data/lib/mongo/util/read_preference.rb +0 -112
- data/lib/mongo/util/socket_util.rb +0 -20
- data/lib/mongo/util/ssl_socket.rb +0 -51
- data/lib/mongo/util/tcp_socket.rb +0 -62
- data/lib/mongo/util/thread_local_variable_manager.rb +0 -11
- data/lib/mongo/util/unix_socket.rb +0 -23
- data/lib/mongo/util/uri_parser.rb +0 -337
- data/test/functional/connection_test.rb +0 -449
- data/test/functional/threading_test.rb +0 -95
- data/test/replica_set/complex_connect_test.rb +0 -64
- data/test/shared/authentication.rb +0 -66
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/util_test.rb +0 -55
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 756bee5f8dcecc237006f5ebfe8d4087ae06f855
|
|
4
|
+
data.tar.gz: c504ef1e1492dee4ff6e5bdab83fac92cdf54069
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d87e98fa9b33d9d446128a61efc85e0b7e0c67ebfd58bc2e42758156a4794d2c5aa09ff4dd3a87900b1593213145d813aa663df58d6d1fb11325441214fc29fe
|
|
7
|
+
data.tar.gz: 07ec6387420ed99a2308266fa50342de858f0fbac16ee308853f2fe36e633901e61c160b67ad292e1cc25b47135ae19267ec08d14fea3cb8a7e3f3b4fa6d4916
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/LICENSE
CHANGED
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
|
|
176
176
|
END OF TERMS AND CONDITIONS
|
|
177
177
|
|
|
178
|
-
Copyright (C) 2008-2013
|
|
178
|
+
Copyright (C) 2008-2013 MongoDB, Inc.
|
|
179
179
|
|
|
180
180
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
181
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
|
@@ -1,342 +1,165 @@
|
|
|
1
|
-
[![Build Status][travis-img]][travis-url] [![
|
|
1
|
+
MongoDB Ruby Driver [![Build Status][travis-img]][travis-url] [![Code Climate][codeclimate-img]][codeclimate-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Gem Version][rubygems-img]][rubygems-url]
|
|
2
|
+
-----
|
|
3
|
+
The officially supported Ruby driver for [MongoDB](http://www.mongodb.org).
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[codeclimate-img]: https://codeclimate.com/github/mongodb/mongo-ruby-driver.png
|
|
6
|
-
[codeclimate-url]: https://codeclimate.com/github/mongodb/mongo-ruby-driver
|
|
7
|
-
[jenkins-img]: https://jenkins.10gen.com/job/mongo-ruby-driver/badge/icon
|
|
8
|
-
[jenkins-url]: https://jenkins.10gen.com/job/mongo-ruby-driver/
|
|
9
|
-
[api-url]: http://api.mongodb.org/ruby/current
|
|
5
|
+
Installation
|
|
6
|
+
-----
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
**Gem Installation**<br>
|
|
9
|
+
The Ruby driver is released and distributed through RubyGems and it can be installed with the following command:
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
that matches the release of the Ruby driver that you are using. Note that the
|
|
16
|
-
[Ruby Language Center for MongoDB](http://www.mongodb.org/display/DOCS/Ruby+Language+Center)
|
|
17
|
-
has a link to API Documentation for the current release.
|
|
18
|
-
|
|
19
|
-
If you have the source, you can generate the matching documentation by typing
|
|
20
|
-
|
|
21
|
-
$ rake docs
|
|
22
|
-
|
|
23
|
-
Once generated, the API documentation can be found in the docs/ folder.
|
|
24
|
-
|
|
25
|
-
# Introduction
|
|
26
|
-
|
|
27
|
-
This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
|
|
28
|
-
|
|
29
|
-
For the api reference please see the [API][api-url]
|
|
30
|
-
|
|
31
|
-
The [wiki](https://github.com/mongodb/mongo-ruby-driver/wiki) has other articles of interest, including:
|
|
32
|
-
|
|
33
|
-
1. [A tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
|
|
34
|
-
2. [Replica Sets in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Replica-Sets).
|
|
35
|
-
3. [Write Concern in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Write-Concern).
|
|
36
|
-
4. [Tailable Cursors in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Tailable-Cursors).
|
|
37
|
-
5. [Read Preference in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Read-Preference).
|
|
38
|
-
6. [GridFS in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/GridFS).
|
|
39
|
-
7. [Frequently Asked Questions](https://github.com/mongodb/mongo-ruby-driver/wiki/FAQ).
|
|
40
|
-
8. [History](https://github.com/mongodb/mongo-ruby-driver/wiki/History).
|
|
41
|
-
9. [Release plan](https://github.com/mongodb/mongo-ruby-driver/wiki/Releases).
|
|
42
|
-
10. [Credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
|
|
43
|
-
|
|
44
|
-
Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial) for much more:
|
|
45
|
-
|
|
46
|
-
```ruby
|
|
47
|
-
require 'rubygems'
|
|
48
|
-
require 'mongo'
|
|
49
|
-
|
|
50
|
-
include Mongo
|
|
51
|
-
|
|
52
|
-
@client = MongoClient.new('localhost', 27017)
|
|
53
|
-
@db = @client['sample-db']
|
|
54
|
-
@coll = @db['test']
|
|
55
|
-
|
|
56
|
-
@coll.remove
|
|
57
|
-
|
|
58
|
-
3.times do |i|
|
|
59
|
-
@coll.insert({'a' => i+1})
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
puts "There are #{@coll.count} records. Here they are:"
|
|
63
|
-
@coll.find.each { |doc| puts doc.inspect }
|
|
11
|
+
```bash
|
|
12
|
+
gem install mongo
|
|
64
13
|
```
|
|
65
14
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### Ruby Versions
|
|
69
|
-
|
|
70
|
-
The driver works and is consistently tested on Ruby 1.8.7 and 1.9.3 as well as JRuby 1.6.x and 1.7.x.
|
|
15
|
+
For a significant performance boost, you'll want to install the C-extension:
|
|
71
16
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### Gems
|
|
75
|
-
|
|
76
|
-
$ gem update --system
|
|
77
|
-
$ gem install mongo
|
|
78
|
-
|
|
79
|
-
For a significant performance boost, you'll want to install the C extension:
|
|
80
|
-
|
|
81
|
-
$ gem install bson_ext
|
|
82
|
-
|
|
83
|
-
Note that bson_ext isn't used with JRuby. Instead, we use some native Java extensions are bundled with the bson gem. If you ever need to modify these extensions, you can recompile with the following rake task:
|
|
84
|
-
|
|
85
|
-
$ rake compile:jbson
|
|
86
|
-
|
|
87
|
-
### From the GitHub source
|
|
88
|
-
|
|
89
|
-
The source code is available at http://github.com/mongodb/mongo-ruby-driver.
|
|
90
|
-
You can either clone the git repository or download a tarball or zip file.
|
|
91
|
-
Once you have the source, you can use it from wherever you downloaded it or
|
|
92
|
-
you can install it as a gem from the source by typing:
|
|
93
|
-
|
|
94
|
-
$ rake install
|
|
95
|
-
|
|
96
|
-
# Examples
|
|
97
|
-
|
|
98
|
-
For extensive examples, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
|
|
99
|
-
|
|
100
|
-
# GridFS
|
|
101
|
-
|
|
102
|
-
The Ruby driver include two abstractions for storing large files: Grid and GridFileSystem.
|
|
103
|
-
|
|
104
|
-
The Grid class is a Ruby implementation of MongoDB's GridFS file storage
|
|
105
|
-
specification. GridFileSystem is essentially the same, but provides a more filesystem-like API and assumes that filenames are unique.
|
|
106
|
-
|
|
107
|
-
An instance of both classes represents an individual file store. See the API reference for details.
|
|
108
|
-
|
|
109
|
-
Examples:
|
|
110
|
-
|
|
111
|
-
```ruby
|
|
112
|
-
# Write a file on disk to the Grid
|
|
113
|
-
file = File.open('image.jpg')
|
|
114
|
-
grid = Mongo::Grid.new(db)
|
|
115
|
-
id = grid.put(file)
|
|
116
|
-
|
|
117
|
-
# Retrieve the file
|
|
118
|
-
file = grid.get(id)
|
|
119
|
-
file.read
|
|
120
|
-
|
|
121
|
-
# Get all the file's metata
|
|
122
|
-
file.filename
|
|
123
|
-
file.content_type
|
|
124
|
-
file.metadata
|
|
17
|
+
```bash
|
|
18
|
+
gem install bson_ext
|
|
125
19
|
```
|
|
126
20
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
## Thread Safety
|
|
21
|
+
**Github Installation**<br>
|
|
22
|
+
For development and test environments (not recommended for production) you can also install the Ruby driver directly from source:
|
|
130
23
|
|
|
131
|
-
|
|
24
|
+
```bash
|
|
25
|
+
# clone the repository
|
|
26
|
+
git clone https://github.com/mongodb/mongo-ruby-driver.git
|
|
27
|
+
cd mongo-ruby-driver
|
|
132
28
|
|
|
133
|
-
|
|
29
|
+
# checkout a specific version by tag (optional)
|
|
30
|
+
git checkout 1.x.x
|
|
134
31
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
timeout for waiting for old connections to be released to the pool.
|
|
32
|
+
# install all development dependencies
|
|
33
|
+
gem install bundler
|
|
34
|
+
bundle install
|
|
139
35
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```ruby
|
|
143
|
-
@client = MongoClient.new("localhost", 27017, :pool_size => 5, :timeout => 5)
|
|
36
|
+
# install the ruby driver
|
|
37
|
+
rake install
|
|
144
38
|
```
|
|
145
39
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
## Forking
|
|
150
|
-
|
|
151
|
-
Certain Ruby application servers work by forking, and it has long been necessary to
|
|
152
|
-
re-establish the child process's connection to the database after fork. But with the release
|
|
153
|
-
of v1.3.0, the Ruby driver detects forking and reconnects automatically.
|
|
154
|
-
|
|
155
|
-
## Environment variable `MONGODB_URI`
|
|
156
|
-
|
|
157
|
-
`Mongo::MongoClient.from_uri`, `Mongo::MongoClient.new` and `Mongo::MongoReplicaSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
|
|
158
|
-
|
|
159
|
-
The URI must fit this specification:
|
|
160
|
-
|
|
161
|
-
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
|
|
162
|
-
|
|
163
|
-
If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::MongoClient.from_uri` because it will return either `Mongo::MongoClient` or a `Mongo::MongoReplicaSetClient` depending on how many hosts are specified. Trying to use `Mongo::MongoClient.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
|
|
164
|
-
|
|
165
|
-
## String Encoding
|
|
40
|
+
To be able to use the driver with Kerberos authentication enabled, install the
|
|
41
|
+
`mongo_kerberos` gem and add it instead of mongo to your application:
|
|
166
42
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
Ruby 1.9 has built-in character encoding support. All strings sent to Mongo
|
|
171
|
-
and received from Mongo are converted to UTF-8 when necessary, and strings
|
|
172
|
-
read from Mongo will have their character encodings set to UTF-8.
|
|
173
|
-
|
|
174
|
-
When used with Ruby 1.8, the bytes in each string are written to and read from
|
|
175
|
-
Mongo as is. If the string is ASCII, all is well, because ASCII is a subset of
|
|
176
|
-
UTF-8. If the string is not ASCII, it may not be a well-formed UTF-8
|
|
177
|
-
string.
|
|
178
|
-
|
|
179
|
-
## Primary Keys
|
|
180
|
-
|
|
181
|
-
The `_id` field is a primary key. It is treated specially by the database, and
|
|
182
|
-
its use makes many operations more efficient. The value of an _id may be of
|
|
183
|
-
any type. The database itself inserts an _id value if none is specified when
|
|
184
|
-
a record is inserted.
|
|
185
|
-
|
|
186
|
-
### Primary Key Factories
|
|
187
|
-
|
|
188
|
-
A primary key factory is a class you supply to a DB object that knows how to
|
|
189
|
-
generate _id values. If you want to control _id values or even their types,
|
|
190
|
-
using a PK factory lets you do so.
|
|
191
|
-
|
|
192
|
-
You can tell the Ruby Mongo driver how to create primary keys by passing in
|
|
193
|
-
the :pk option to the MongoClient#db method.
|
|
194
|
-
|
|
195
|
-
```ruby
|
|
196
|
-
include Mongo
|
|
197
|
-
db = MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
|
|
43
|
+
```bash
|
|
44
|
+
gem install mongo_kerberos
|
|
198
45
|
```
|
|
199
46
|
|
|
200
|
-
A primary key factory object must respond to :create_pk, which should
|
|
201
|
-
take a hash and return a hash which merges the original hash with any
|
|
202
|
-
primary key fields the factory wishes to inject.
|
|
203
|
-
|
|
204
|
-
NOTE: if the object already has a primary key, the factory should not
|
|
205
|
-
inject a new key; this means that the object may already exist in the
|
|
206
|
-
database. The idea here is that whenever a record is inserted, the
|
|
207
|
-
:pk object's +create_pk+ method will be called and the new hash
|
|
208
|
-
returned will be inserted.
|
|
209
|
-
|
|
210
|
-
Here is a sample primary key factory, taken from the tests:
|
|
211
|
-
```ruby
|
|
212
|
-
class TestPKFactory
|
|
213
|
-
def create_pk(doc)
|
|
214
|
-
doc['_id'] ||= BSON::ObjectId.new
|
|
215
|
-
doc
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
```
|
|
219
|
-
Here's a slightly more sophisticated one that handles both symbol and string
|
|
220
|
-
keys. This is the PKFactory that comes with the MongoRecord code (an
|
|
221
|
-
ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
|
|
222
|
-
(for Rails):
|
|
223
47
|
```ruby
|
|
224
|
-
|
|
225
|
-
def create_pk(doc)
|
|
226
|
-
return doc if doc[:_id]
|
|
227
|
-
doc.delete(:_id) # in case it exists but the value is nil
|
|
228
|
-
doc['_id'] ||= BSON::ObjectId.new
|
|
229
|
-
doc
|
|
230
|
-
end
|
|
231
|
-
end
|
|
48
|
+
require 'mongo_kerberos'
|
|
232
49
|
```
|
|
233
50
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
driver can set the PK factory after obtaining the database but before using it
|
|
238
|
-
for the first time.
|
|
239
|
-
|
|
240
|
-
## The DB Class
|
|
241
|
-
|
|
242
|
-
### Strict mode
|
|
243
|
-
|
|
244
|
-
_**NOTE:** Support for strict mode has been deprecated and will be removed in version 2.0 of the driver._
|
|
245
|
-
|
|
246
|
-
Each database has an optional strict mode. If strict mode is on, then asking
|
|
247
|
-
for a collection that does not exist will raise an error, as will asking to
|
|
248
|
-
create a collection that already exists. Note that both these operations are
|
|
249
|
-
completely harmless; strict mode is a programmer convenience only.
|
|
250
|
-
|
|
251
|
-
To turn on strict mode, either pass in :strict => true when obtaining a DB
|
|
252
|
-
object or call the `:strict=` method:
|
|
51
|
+
Usage
|
|
52
|
+
-----
|
|
53
|
+
Here is a quick example of basic usage for the Ruby driver:
|
|
253
54
|
|
|
254
55
|
```ruby
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
db.strict = false
|
|
258
|
-
# No, I'm not!
|
|
259
|
-
db.strict = true
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
The method DB#strict? returns the current value of that flag.
|
|
263
|
-
|
|
264
|
-
## Cursors
|
|
56
|
+
require 'mongo'
|
|
57
|
+
include Mongo
|
|
265
58
|
|
|
266
|
-
|
|
59
|
+
# connecting to the database
|
|
60
|
+
client = MongoClient.new # defaults to localhost:27017
|
|
61
|
+
db = client['example-db']
|
|
62
|
+
coll = db['example-collection']
|
|
267
63
|
|
|
268
|
-
|
|
64
|
+
# inserting documents
|
|
65
|
+
10.times { |i| coll.insert({ :count => i+1 }) }
|
|
269
66
|
|
|
270
|
-
|
|
271
|
-
|
|
67
|
+
# finding documents
|
|
68
|
+
puts "There are #{coll.count} total documents. Here they are:"
|
|
69
|
+
coll.find.each { |doc| puts doc.inspect }
|
|
272
70
|
|
|
273
|
-
|
|
274
|
-
|
|
71
|
+
# updating documents
|
|
72
|
+
coll.update({ :count => 5 }, { :count => 'foobar' })
|
|
275
73
|
|
|
276
|
-
|
|
74
|
+
# removing documents
|
|
75
|
+
coll.remove({ :count => 8 })
|
|
76
|
+
coll.remove
|
|
77
|
+
```
|
|
277
78
|
|
|
278
|
-
|
|
279
|
-
|
|
79
|
+
Wiki - Tutorials & Examples
|
|
80
|
+
-----
|
|
81
|
+
For many more usage examples and a full tutorial, please visit our [wiki](https://github.com/mongodb/mongo-ruby-driver/wiki).<br>
|
|
280
82
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
83
|
+
API Reference Documentation
|
|
84
|
+
-----
|
|
85
|
+
For API reference documentation, please visit [here](http://api.mongodb.org/ruby).
|
|
284
86
|
|
|
285
|
-
|
|
87
|
+
Compatibility
|
|
88
|
+
-----
|
|
89
|
+
The MongoDB Ruby driver requires Ruby 1.8.7 or greater and is regularly tested against the platforms and environments listed below.
|
|
286
90
|
|
|
287
|
-
|
|
91
|
+
Ruby Platforms | Operating Systems | Architectures
|
|
92
|
+
-------------- | ----------------- | -------------
|
|
93
|
+
MRI 1.8.7, 1.9.3, 2.0.0<br>JRuby 1.7.x | Windows<br>Linux<br>OS X | x86<br>x64<br>ARM
|
|
288
94
|
|
|
289
|
-
|
|
95
|
+
Support & Feedback
|
|
96
|
+
-----
|
|
290
97
|
|
|
291
|
-
|
|
98
|
+
**Support Channels**
|
|
292
99
|
|
|
293
|
-
|
|
100
|
+
For issues, questions or feedback related to the Ruby driver, please look into our [support channels](http://www.mongodb.org/about/support).
|
|
101
|
+
Please do not email any of the Ruby developers directly with issues or questions. You'll get a quicker answer on the [mongodb-user list](http://groups.google.com/group/mongodb-user) Google Group.
|
|
294
102
|
|
|
295
|
-
|
|
103
|
+
Bugs & Feature Requests
|
|
104
|
+
-----
|
|
296
105
|
|
|
297
|
-
|
|
106
|
+
Do you have a bug to report or a feature request to make?
|
|
298
107
|
|
|
299
|
-
|
|
108
|
+
1. Visit [our issue tracker](https://jira.mongodb.org) and login (or create an account if necessary).
|
|
109
|
+
2. Navigate to the [RUBY](https://jira.mongodb.org/browse/RUBY) project.
|
|
110
|
+
3. Click 'Create Issue' and fill out all the applicable form fields.
|
|
300
111
|
|
|
301
|
-
|
|
302
|
-
$ rake test:functional
|
|
112
|
+
When reporting an issue, please keep in mind that all information in JIRA for all driver projects (ex. RUBY, CSHARP, JAVA) and the Core Server (ex. SERVER) project is **PUBLICLY** visible.
|
|
303
113
|
|
|
304
|
-
|
|
114
|
+
**HOW TO ASK FOR HELP**
|
|
305
115
|
|
|
306
|
-
|
|
116
|
+
Providing enough information so we can reproduce the issue immediately will reduce roundtrip communications and get you a useful response as quickly as possible.
|
|
117
|
+
That said, please provide the following information when logging an issue:
|
|
307
118
|
|
|
308
|
-
|
|
119
|
+
1. Environment
|
|
120
|
+
2. Ruby version, including patch-level
|
|
121
|
+
3. MongoDB version
|
|
122
|
+
4. A test case or code snippets
|
|
123
|
+
5. Stack traces and log data, keeping in mind that this info is public
|
|
309
124
|
|
|
310
|
-
|
|
125
|
+
**PLEASE DO NOT**
|
|
311
126
|
|
|
312
|
-
|
|
127
|
+
* Provide any sensitive data or server logs.
|
|
128
|
+
* Report potential security issues publicly (see 'Security Issues').
|
|
313
129
|
|
|
314
|
-
|
|
130
|
+
**EXAMPLE BUG REPORT**
|
|
315
131
|
|
|
316
|
-
|
|
132
|
+
Example taken from [RUBY-775](https://jira.mongodb.org/browse/RUBY-775)
|
|
317
133
|
|
|
318
|
-
|
|
134
|
+
```
|
|
135
|
+
There appears to be a recursive locking condition in the replica set connection pooling.
|
|
319
136
|
|
|
320
|
-
|
|
137
|
+
Environment: AWS Linux 3.10.37-47.135.amzn1.x86_64 / jruby-1.7.12 / JDK java-1.7.0-openjdk-1.7.0.55-2.4.7.1.40.amzn1.x86_64
|
|
321
138
|
|
|
322
|
-
|
|
139
|
+
Component: Connection Pooling / Replica set
|
|
323
140
|
|
|
324
|
-
|
|
141
|
+
Here is a stack trace:
|
|
142
|
+
https://gist.githubusercontent.com/cheald/5ed01172c5b2c9943c87/raw/63075158dac4c78c1775cac8bf84ba3b6537bc1e/gistfile1.txt
|
|
325
143
|
|
|
326
|
-
|
|
144
|
+
The original lock occurs [here](https://github.com/mongodb/mongo-ruby-driver/blob/1.x-stable/lib/mongo/connection/pool_manager.rb#L60)
|
|
327
145
|
|
|
328
|
-
|
|
146
|
+
and then the process of reconnecting ends up attempting to resynchronize the same lock [here](https://github.com/mongodb/mongo-ruby-driver/blob/1.x-stable/lib/mongo/connection/pool_manager.rb#L150)
|
|
147
|
+
```
|
|
329
148
|
|
|
330
|
-
|
|
149
|
+
Security Issues
|
|
150
|
+
-----
|
|
331
151
|
|
|
152
|
+
If you’ve identified a potential security related issue in a driver or any other MongoDB project, please report it by following the [instructions here](http://docs.mongodb.org/manual/tutorial/create-a-vulnerability-report).
|
|
332
153
|
|
|
333
|
-
|
|
154
|
+
Release History
|
|
155
|
+
-----
|
|
334
156
|
|
|
335
|
-
|
|
157
|
+
Full release notes and release history are available [here](https://github.com/mongodb/mongo-ruby-driver/releases).
|
|
336
158
|
|
|
337
|
-
|
|
159
|
+
License
|
|
160
|
+
-----
|
|
338
161
|
|
|
339
|
-
Copyright (C)
|
|
162
|
+
Copyright (C) 2009-2013 MongoDB, Inc.
|
|
340
163
|
|
|
341
164
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
342
165
|
you may not use this file except in compliance with the License.
|
|
@@ -349,3 +172,12 @@ See [credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
|
|
|
349
172
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
350
173
|
See the License for the specific language governing permissions and
|
|
351
174
|
limitations under the License.
|
|
175
|
+
|
|
176
|
+
[rubygems-img]: https://badge.fury.io/rb/mongo.png
|
|
177
|
+
[rubygems-url]: http://badge.fury.io/rb/mongo
|
|
178
|
+
[travis-img]: https://secure.travis-ci.org/mongodb/mongo-ruby-driver.png?branch=1.x-stable
|
|
179
|
+
[travis-url]: http://travis-ci.org/mongodb/mongo-ruby-driver?branch=1.x-stable
|
|
180
|
+
[codeclimate-img]: https://codeclimate.com/github/mongodb/mongo-ruby-driver.png?branch=1.x-stable
|
|
181
|
+
[codeclimate-url]: https://codeclimate.com/github/mongodb/mongo-ruby-driver?branch=1.x-stable
|
|
182
|
+
[coveralls-img]: https://coveralls.io/repos/mongodb/mongo-ruby-driver/badge.png?branch=1.x-stable
|
|
183
|
+
[coveralls-url]: https://coveralls.io/r/mongodb/mongo-ruby-driver?branch=1.x-stable
|
data/Rakefile
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Copyright (C) 2009-2013 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.
|
|
2
14
|
|
|
3
15
|
require 'rubygems'
|
|
4
16
|
|
|
5
17
|
begin
|
|
6
18
|
require 'bundler'
|
|
7
19
|
rescue LoadError
|
|
8
|
-
raise '[FAIL] Bundler not found! Install it with `gem install bundler
|
|
20
|
+
raise '[FAIL] Bundler not found! Install it with `gem install bundler && bundle`.'
|
|
9
21
|
end
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
rake_tasks = Dir.glob(File.join('tasks', '**', '*.rake')).sort
|
|
24
|
+
if ENV.keys.any? { |k| k.end_with?('_CI') }
|
|
12
25
|
Bundler.require(:default, :testing)
|
|
26
|
+
rake_tasks.reject! { |r| r =~ /deploy/ }
|
|
13
27
|
else
|
|
14
28
|
Bundler.require(:default, :testing, :deploy, :development)
|
|
15
29
|
end
|
|
16
30
|
|
|
17
|
-
|
|
31
|
+
rake_tasks.each { |rake| load File.expand_path(rake) }
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.12.5
|
data/bin/mongo_console
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
2
17
|
org_argv = ARGV.dup
|
|
3
18
|
ARGV.clear
|
|
4
19
|
|
|
5
|
-
require 'irb'
|
|
6
|
-
|
|
7
20
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
8
|
-
require 'mongo'
|
|
9
21
|
|
|
22
|
+
require 'mongo'
|
|
10
23
|
include Mongo
|
|
11
24
|
|
|
12
25
|
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
|
@@ -17,5 +30,14 @@ puts "Connecting to #{host}:#{port} (CLIENT) on with database #{dbnm} (DB)"
|
|
|
17
30
|
CLIENT = MongoClient.new(host, port)
|
|
18
31
|
DB = CLIENT.db(dbnm)
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
# try pry if available, fall back to irb
|
|
34
|
+
begin
|
|
35
|
+
require 'pry'
|
|
36
|
+
CONSOLE_CLASS = Pry
|
|
37
|
+
rescue LoadError
|
|
38
|
+
require 'irb'
|
|
39
|
+
CONSOLE_CLASS = IRB
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
puts "Starting #{CONSOLE_CLASS.name} session..."
|
|
43
|
+
CONSOLE_CLASS.start(__FILE__)
|