| Module | Mongo::Collection::View::Writable |
| In: |
lib/mongo/collection/view/writable.rb
|
Defines write related behavior for collection view.
@since 2.0.0
| ARRAY_FILTERS | = | 'array_filters'.freeze |
The array filters field constant.
@since 2.5.0 |
Remove documents from the collection.
@example Remove multiple documents from the collection.
collection_view.delete_many
@param [ Hash ] opts The options.
@option opts [ Hash ] :collation The collation to use.
@return [ Result ] The response from the database.
@since 2.0.0
Remove a document from the collection.
@example Remove a single document from the collection.
collection_view.delete_one
@param [ Hash ] opts The options.
@option opts [ Hash ] :collation The collation to use.
@return [ Result ] The response from the database.
@since 2.0.0
Finds a single document in the database via findAndModify and deletes it, returning the original document.
@example Find one document and delete it.
view.find_one_and_delete
@param [ Hash ] opts The options.
@option opts [ Hash ] :collation The collation to use.
@return [ BSON::Document, nil ] The document, if found.
@since 2.0.0
Finds a single document and replaces it.
@example Find a document and replace it, returning the original.
view.find_one_and_replace({ name: 'test' }, :return_document => :before)
@example Find a document and replace it, returning the new document.
view.find_one_and_replace({ name: 'test' }, :return_document => :after)
@param [ BSON::Document ] replacement The replacement. @param [ Hash ] opts The options.
@option opts [ Symbol ] :return_document Either :before or :after. @option opts [ true, false ] :upsert Whether to upsert if the document doesn‘t exist. @option opts [ true, false ] :bypass_document_validation Whether or
not to skip document level validation.
@option opts [ Hash ] :write_concern The write concern options.
Defaults to the collection's write concern.
@option opts [ Hash ] :collation The collation to use.
@return [ BSON::Document ] The document.
@since 2.0.0
Finds a single document and updates it.
@example Find a document and update it, returning the original.
view.find_one_and_update({ "$set" => { name: 'test' }}, :return_document => :before)
@param [ BSON::Document ] document The updates. @param [ Hash ] opts The options.
@option opts [ Symbol ] :return_document Either :before or :after. @option opts [ true, false ] :upsert Whether to upsert if the document doesn‘t exist. @option opts [ true, false ] :bypass_document_validation Whether or
not to skip document level validation.
@option opts [ Hash ] :write_concern The write concern options.
Defaults to the collection's write concern.
@option opts [ Hash ] :collation The collation to use. @option opts [ Array ] :array_filters A set of filters specifying to which array elements an update should apply.
@return [ BSON::Document ] The document.
@since 2.0.0
Replaces a single document in the database with the new document.
@example Replace a single document.
collection_view.replace_one({ name: 'test' })
@param [ Hash ] replacement The replacement document. @param [ Hash ] opts The options.
@option opts [ true, false ] :upsert Whether to upsert if the
document doesn't exist.
@option opts [ Hash ] :collation The collation to use.
@return [ Result ] The response from the database.
@since 2.0.0
Update documents in the collection.
@example Update multiple documents in the collection.
collection_view.update_many('$set' => { name: 'test' })
@param [ Hash ] spec The update statement. @param [ Hash ] opts The options.
@option opts [ true, false ] :upsert Whether to upsert if the
document doesn't exist.
@option opts [ Hash ] :collation The collation to use. @option opts [ Array ] :array_filters A set of filters specifying to which array elements
an update should apply.
@return [ Result ] The response from the database.
@since 2.0.0
Update a single document in the collection.
@example Update a single document in the collection.
collection_view.update_one('$set' => { name: 'test' })
@param [ Hash ] spec The update statement. @param [ Hash ] opts The options.
@option opts [ true, false ] :upsert Whether to upsert if the
document doesn't exist.
@option opts [ Hash ] :collation The collation to use. @option opts [ Array ] :array_filters A set of filters specifying to which array elements
an update should apply.
@return [ Result ] The response from the database.
@since 2.0.0