Merge branch 'master' of github.com:mongodb/mongo-ruby-driver into 361-uri-parser
This commit is contained in:
commit
6f80a48fce
|
@ -333,6 +333,10 @@ module Mongo
|
|||
# @option opts [Boolean] :continue_on_error (+false+) If true, then
|
||||
# continue a bulk insert even if one of the documents inserted
|
||||
# triggers a database assertion (as in a duplicate insert, for instance).
|
||||
# If not using safe mode, the list of ids returned will
|
||||
# include the object ids of all documents attempted on insert, even
|
||||
# if some are rejected on error. When safe mode is
|
||||
# enabled, any error will raise an OperationFailure exception.
|
||||
# MongoDB v2.0+.
|
||||
#
|
||||
# @core insert insert-instance_method
|
||||
|
@ -624,7 +628,12 @@ module Mongo
|
|||
if raw
|
||||
result
|
||||
elsif result["result"]
|
||||
if result['result'].is_a? BSON::OrderedHash and result['result'].has_key? 'db' and result['result'].has_key? 'collection'
|
||||
otherdb = @db.connection[result['result']['db']]
|
||||
otherdb[result['result']['collection']]
|
||||
else
|
||||
@db[result["result"]]
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Could not instantiate collection from result. If you specified " +
|
||||
"{:out => {:inline => true}}, then you must also specify :raw => true to get the results."
|
||||
|
|
|
@ -604,6 +604,8 @@ module Mongo
|
|||
def check_is_master(node)
|
||||
begin
|
||||
host, port = *node
|
||||
socket = nil
|
||||
config = nil
|
||||
|
||||
if @connect_timeout
|
||||
Mongo::TimeoutHandler.timeout(@connect_timeout, OperationTimeout) do
|
||||
|
|
|
@ -37,9 +37,6 @@ module Mongo
|
|||
end
|
||||
end
|
||||
|
||||
# Raised when configuration options cause connections, queries, etc., to fail.
|
||||
class ConfigurationError < MongoRubyError; end
|
||||
|
||||
# Raised on fatal errors to GridFS.
|
||||
class GridError < MongoRubyError; end
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ module Mongo
|
|||
opts = opts.dup
|
||||
filename = opts[:filename]
|
||||
opts.merge!(default_grid_io_opts)
|
||||
file = GridIO.new(@files, @chunks, filename, 'w', opts=opts)
|
||||
file = GridIO.new(@files, @chunks, filename, 'w', opts)
|
||||
file.write(data)
|
||||
file.close
|
||||
file.files_id
|
||||
|
|
|
@ -151,6 +151,19 @@ class TestCollection < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_bulk_insert
|
||||
@@test.remove
|
||||
docs = []
|
||||
docs << {:foo => 1}
|
||||
docs << {:foo => 2}
|
||||
docs << {:foo => 3}
|
||||
response = @@test.insert(docs)
|
||||
assert_equal 3, response.length
|
||||
assert response.all? {|id| id.is_a?(BSON::ObjectId)}
|
||||
assert_equal 3, @@test.count
|
||||
@@test.remove
|
||||
end
|
||||
|
||||
def test_bulk_insert_with_continue_on_error
|
||||
if @@version >= "2.0"
|
||||
@@test.create_index([["foo", 1]], :unique => true)
|
||||
|
@ -546,6 +559,19 @@ class TestCollection < Test::Unit::TestCase
|
|||
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
||||
assert res["results"]
|
||||
end
|
||||
|
||||
def test_map_reduce_with_collection_output_to_other_db
|
||||
@@test << {:user_id => 1}
|
||||
@@test << {:user_id => 2}
|
||||
|
||||
m = Code.new("function() { emit(this.user_id, 1); }")
|
||||
r = Code.new("function(k,vals) { return 1; }")
|
||||
res = @@test.map_reduce(m, r, :out => {:replace => 'foo', :db => 'somedb'})
|
||||
assert res["result"]
|
||||
assert res["counts"]
|
||||
assert res["timeMillis"]
|
||||
assert res.find.to_a.any? {|doc| doc["_id"] == 2 && doc["value"] == 1}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue