================================
MongoDB\\Collection::insertOne()
================================

.. default-domain:: mongodb
                    
.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: singlecol

              
Definition
----------

.. phpmethod:: MongoDB\\Collection::insertOne
   
   Inserts one document.
   
   .. code-block:: php
                   
      function insertOne($document, array $options = []): MongoDB\InsertOneResult

   ``insertOne()`` supports the following parameters:
   
   .. include:: /includes/apiargs/MongoDBCollection-method-insertOne-param.rst

   The ``$options`` parameter supports the following options:
                
   .. include:: /includes/apiargs/MongoDBCollection-method-insertOne-option.rst

Output
------

Returns a ``MongoDB\InsertOneResult`` object.

Example
-------

The following operation inserts a document into the ``users``
collection in the ``example`` database:

.. include:: /includes/example-insertOne.rst

.. seealso::
   
   - :phpmethod:`MongoDB\\Collection::bulkWrite`
   - :phpmethod:`MongoDB\\Collection::insertMany`
   - :doc:`/tutorial/crud`
   - :manual:`insert </reference/command/insert>` command reference
     in the MongoDB manual
