{
    "mode": "perldoc",
    "parameter": "MongoDB::BulkWrite",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MongoDB%3A%3ABulkWrite/json",
    "generated": "2026-06-09T15:19:40Z",
    "synopsis": "use Safe::Isa;\nuse Try::Tiny;\nmy $bulk = $collection->initializeorderedbulkop;\n$bulk->insertone( $doc );\n$bulk->find( $query )->upsert->replaceone( $doc )\n$bulk->find( $query )->update( $modification )\nmy $result = try {\n$bulk->execute;\n}\ncatch {\nif ( $->$isa(\"MongoDB::WriteConcernError\") ) {\nwarn \"Write concern failed\";\n}\nelse {\ndie $;\n}\n};",
    "sections": {
        "NAME": {
            "content": "MongoDB::BulkWrite - MongoDB bulk write interface\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version v2.2.2\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Safe::Isa;\nuse Try::Tiny;\n\nmy $bulk = $collection->initializeorderedbulkop;\n\n$bulk->insertone( $doc );\n$bulk->find( $query )->upsert->replaceone( $doc )\n$bulk->find( $query )->update( $modification )\n\nmy $result = try {\n$bulk->execute;\n}\ncatch {\nif ( $->$isa(\"MongoDB::WriteConcernError\") ) {\nwarn \"Write concern failed\";\n}\nelse {\ndie $;\n}\n};\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This class constructs a list of write operations to perform in bulk for a single collection. On\na MongoDB 2.6 or later server with write command support this allow grouping similar operations\ntogether for transit to the database, minimizing network round-trips.\n\nTo begin a bulk operation, use one these methods from MongoDB::Collection:\n\n*   initializeorderedbulkop\n\n*   initializeunorderedbulkop\n",
            "subsections": [
                {
                    "name": "Ordered Operations",
                    "content": "With an ordered operations list, MongoDB executes the write operations in the list serially. If\nan error occurs during the processing of one of the write operations, MongoDB will return\nwithout processing any remaining write operations in the list.\n"
                },
                {
                    "name": "Unordered Operations",
                    "content": "With an unordered operations list, MongoDB can execute in parallel, as well as in a\nnondeterministic order, the write operations in the list. If an error occurs during the\nprocessing of one of the write operations, MongoDB will continue to process remaining write\noperations in the list.\n"
                }
            ]
        },
        "ATTRIBUTES": {
            "content": "collection (required)\nThe MongoDB::Collection where the operations are to be performed.\n\nordered (required)\nA boolean for whether or not operations should be ordered (true) or unordered (false).\n\nbypassDocumentValidation\nA boolean for whether or not operations should bypass document validation. Default is false.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "find\n$view = $bulk->find( $querydocument );\n\nThe \"find\" method returns a MongoDB::BulkWriteView object that allows write operations like\n\"update\" or \"remove\", constrained by a query document.\n\nA query document is required. Use an empty hashref for no criteria:\n\n$bulk->find( {} )->remove; # remove all documents!\n\nAn exception will be thrown on error.\n\ninsertone\n$bulk->insertone( $doc );\n\nQueues a document for insertion when \"execute\" is called. The document may be a hash reference,\nan array reference (with balanced key/value pairs) or a Tie::IxHash object. If the document does\nnot have an \"id\" field, one will be added to the original.\n\nThe method has an empty return on success; an exception will be thrown on error.\n\nexecute\nmy $result = $bulk->execute;\n# Optional write concern:\nmy $result = $bulk->execute( $concern );\n# With options\nmy $result = $bulk->execute( $concern, $options );\n\nExecutes the queued operations. The order and semantics depend on whether the bulk object is\nordered or unordered:\n\n*   ordered — operations are executed in order, but operations of the same type (e.g. multiple\ninserts) may be grouped together and sent to the server. If the server returns an error, the\nbulk operation will stop and an error will be thrown.\n\n*   unordered — operations are grouped by type and sent to the server in an unpredictable order.\nAfter all operations are sent, if any errors occurred, an error will be thrown.\n\nWhen grouping operations of a type, operations will be sent to the server in batches not\nexceeding 16MiB or 1000 items (for a version 2.6 or later server) or individually (for legacy\nservers without write command support).\n\nA write concern is optional, and can either take a pre-constructed WriteConcern object, or the\narguments to construct one. For information on write concerns, see MongoDB::WriteConcern.\n\nThe options argument is an optional hashref which can contain the following values:\n\n*   \"session\" - the session to use for these operations. If not supplied, will use an implicit\nsession. For more information see MongoDB::ClientSession\n\nThis method returns a MongoDB::BulkWriteResult object if the bulk operation executes\nsuccessfully.\n\nTypical errors might include:\n\n*   \"MongoDB::WriteError\" — one or more write operations failed\n\n*   \"MongoDB::WriteConcernError\" - all writes were accepted by a primary, but the write concern\nfailed\n\n*   \"MongoDB::DatabaseError\" — a command to the database failed entirely\n\nSee MongoDB::Error for more on error handling.\n\nNOTE: it is an error to call \"execute\" without any operations or to call \"execute\" more than\nonce on the same bulk object.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   David Golden <david@mongodb.com>\n\n*   Rassi <rassi@mongodb.com>\n\n*   Mike Friedman <friedo@friedo.com>\n\n*   Kristina Chodorow <k.chodorow@gmail.com>\n\n*   Florian Ragwitz <rafl@debian.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2020 by MongoDB, Inc.\n\nThis is free software, licensed under:\n\nThe Apache License, Version 2.0, January 2004\n",
            "subsections": []
        }
    },
    "summary": "MongoDB::BulkWrite - MongoDB bulk write interface",
    "flags": [],
    "examples": [],
    "see_also": []
}