lib/mongo/collection.rb
# Insert a single document into the collection.
#
# @example Insert a document into the collection.
#   collection.insert_one({ name: 'test' })
#
# @param [ Hash ] document The document to insert.
# @param [ Hash ] opts The insert options.
#
# @option opts [ Session ] :session The session to use for the operation.
#
# @return [ Result ] The database response wrapper.
#
# @since 2.0.0
Insert a single document into the collection.
Insert a single document into the collection .
def insert_one(document, opts = {})
      QueryCache.clear_namespace(namespace)
      client.send(:with_session, opts) do |session|
        write_concern = if opts[:write_concern]
          WriteConcern.get(opts[:write_concern])
        else
          write_concern_with_session(session)
        end
        if document.nil?
          raise ArgumentError, "Document to be inserted cannot be nil"
        end
        write_with_retry(session, write_concern) do |server, txn_num|
          Operation::Insert.new(
            :documents => [ document ],
            :db_name => database.name,
            :coll_name => name,
            :write_concern => write_concern,
            :bypass_document_validation => !!opts[:bypass_document_validation],
            :options => opts,
            :id_generator => client.options[:id_generator],
            :session => session,
            :txn_num => txn_num,
          ).execute(server, context: Operation::Context.new(client: client, session: session))
        end
      end
    end
def insert_one ( document , opts = { } ) QueryCache . clear_namespace ( namespace ) client . send ( :with_session , opts ) do | session | write_concern = if opts [ :write_concern ] WriteConcern . get ( opts [ :write_concern ] ) else write_concern_with_session ( session ) end if document . nil? raise ArgumentError , "Document to be inserted cannot be nil" end write_with_retry ( session , write_concern ) do | server , txn_num | Operation :: Insert . new ( :documents => [ document ] , :db_name => database . name , :coll_name => name , :write_concern => write_concern , :bypass_document_validation => ! ! opts [ :bypass_document_validation ] , :options => opts , :id_generator => client . options [ :id_generator ] , :session => session , :txn_num => txn_num , ) . execute ( server , context : Operation :: Context . new ( client : client , session : session ) ) end end end
Insert a single document into the collection.
Insert a single document into the collection .
The database response wrapper.
The database response wrapper .
 Result 
document
<not_specific>
opts
:session The session to use for the operation.
: session The session to use for the operation .
<not_specific>
opts The insert options.
opts The insert options .
example
Insert a document into the collection. collection.insert_one({ name: 'test' })
Insert a document into the collection . collection . insert_one ( { name : ' test ' } )
since
None