123456789_123456789_123456789_123456789_123456789_

Class: Mongo::BulkWrite::Result

Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/bulk_write/result.rb

Overview

Wraps a series of bulk write operations in a result object.

Since:

  • 2.0.6

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#acknowledged?Boolean (readonly)

Returns:

  • (Boolean)

    Is the result acknowledged?

Since:

  • 2.0.6

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 27

def acknowledged?
  @acknowledged
end

Instance Method Details

#deleted_countInteger

Returns the number of documents deleted.

Examples:

Get the number of deleted documents.

result.deleted_count

Returns:

  • (Integer)

    The number deleted.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 92

def deleted_count
  @results[REMOVED_COUNT]
end

#inserted_countInteger

Returns the number of documents inserted.

Examples:

Get the number of inserted documents.

result.inserted_count

Returns:

  • (Integer)

    The number inserted.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 120

def inserted_count
  @results[INSERTED_COUNT]
end

#inserted_idsArray<BSON::ObjectId>

Get the inserted document ids, if the operation has inserts.

Examples:

Get the inserted ids.

result.inserted_ids

Returns:

  • (Array<BSON::ObjectId>)

    The inserted ids.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 132

def inserted_ids
  @results[INSERTED_IDS]
end

#matched_countInteger

Returns the number of documents matched.

Examples:

Get the number of matched documents.

result.matched_count

Returns:

  • (Integer)

    The number matched.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 144

def matched_count
  @results[MATCHED_COUNT]
end

#modified_countInteger

Returns the number of documents modified.

Examples:

Get the number of modified documents.

result.modified_count

Returns:

  • (Integer)

    The number modified.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 156

def modified_count
  @results[MODIFIED_COUNT]
end

#upserted_countInteger

Returns the number of documents upserted.

Examples:

Get the number of upserted documents.

result.upserted_count

Returns:

  • (Integer)

    The number upserted.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 168

def upserted_count
  @results[UPSERTED_COUNT]
end

#upserted_idsArray<BSON::ObjectId>

Get the upserted document ids, if the operation has inserts.

Examples:

Get the upserted ids.

result.upserted_ids

Returns:

  • (Array<BSON::ObjectId>)

    The upserted ids.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 180

def upserted_ids
  @results[UPSERTED_IDS] || []
end

#validate!Result

Validates the bulk write result.

Examples:

Validate the result.

result.validate!

Returns:

  • (Result)

    The result.

Raises:

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/result.rb', line 194

def validate!
  if @results['writeErrors'] || @results['writeConcernErrors']
    raise Error::BulkWriteError.new(@results)
  else
    self
  end
end