class Mongo::Operation::Write::Bulk::Update::Result
Defines custom behaviour of results when updating.
@since 2.0.0
Constants
- MODIFIED
The number of modified docs field in the result.
@since 2.0.0
- UPSERTED
The upserted docs field in the result.
@since 2.0.0
Public Instance Methods
Gets the number of documents matched.
@example Get the matched count.
result.n_matched
@return [ Integer ] The number of documents matched.
@since 2.0.0
# File lib/mongo/operation/write/bulk/update/result.rb, line 64 def n_matched return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) reply.documents.first[N] - n_upserted else if reply.documents.first[N] n += reply.documents.first[N] else n end end end end
Gets the number of documents modified. Not that in a mixed sharded cluster a call to update could return nModified (>= 2.6) or not (<= 2.4). If any call does not return nModified we can't report a valid final count so set the field to nil.
@example Get the modified count.
result.n_modified
@return [ Integer ] The number of documents modified.
@since 2.0.0
# File lib/mongo/operation/write/bulk/update/result.rb, line 91 def n_modified return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if n && reply.documents.first[MODIFIED] n += reply.documents.first[MODIFIED] else nil end end end
Gets the number of documents upserted.
@example Get the upserted count.
result.n_upserted
@return [ Integer ] The number of documents upserted.
@since 2.0.0
# File lib/mongo/operation/write/bulk/update/result.rb, line 45 def n_upserted return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) n += reply.documents.first[UPSERTED].size else n end end end
Get the upserted documents.
@example Get upserted documents.
result.upserted
@return [ Array<BSON::Document> ] The upserted document info
@since 2.1.0
# File lib/mongo/operation/write/bulk/update/result.rb, line 110 def upserted reply.documents.first[UPSERTED] || [] end
Private Instance Methods
# File lib/mongo/operation/write/bulk/update/result.rb, line 116 def upsert?(reply) upserted.any? end