lib/mongo/collection.rb
# Force the collection to be created in the database.
#
# @example Force the collection to be created.
#   collection.create
#
# @param [ Hash ] opts The options for the create operation.
#
# @option opts [ Session ] :session The session to use for the operation.
# @option opts [ Hash ] :write_concern The write concern options.
# @option opts [ Hash ] :time_series Create a time-series collection.
# @option opts [ Integer ] :expire_after Number indicating
#   after how many seconds old time-series data should be deleted.
#
# @return [ Result ] The result of the command.
#
# @since 2.0.0
Force the collection to be created in the database.
Force the collection to be created in the database .
def create(opts = {})
      options = Hash[self.options.reject do |key, value|
        %w(read read_preference read_concern).include?(key.to_s)
      end]
      options.update(Utils.slice_hash(opts, *TIME_SERIES_OPTIONS.keys))
      TIME_SERIES_OPTIONS.each do |ruby_key, server_key|
        if options.key?(ruby_key)
          options[server_key] = options.delete(ruby_key)
        end
      end
      operation = { :create => name }.merge(options)
      operation.delete(:write)
      operation.delete(:write_concern)
      client.send(:with_session, opts) do |session|
        write_concern = if opts[:write_concern]
          WriteConcern.get(opts[:write_concern])
        else
          self.write_concern
        end
        context = Operation::Context.new(client: client, session: session)
        Operation::Create.new(
          selector: operation,
          db_name: database.name,
          write_concern: write_concern,
          session: session,
          collation: options[:collation] || options['collation'],
        ).execute(next_primary(nil, session), context: context)
      end
    end
def create ( opts = { } ) options = Hash [ self . options . reject do | key , value | %w( read read_preference read_concern ) . include? ( key . to_s ) end ] options . update ( Utils . slice_hash ( opts , * TIME_SERIES_OPTIONS . keys ) ) TIME_SERIES_OPTIONS . each do | ruby_key , server_key | if options . key? ( ruby_key ) options [ server_key ] = options . delete ( ruby_key ) end end operation = { :create => name } . merge ( options ) operation . delete ( :write ) operation . delete ( :write_concern ) client . send ( :with_session , opts ) do | session | write_concern = if opts [ :write_concern ] WriteConcern . get ( opts [ :write_concern ] ) else self . write_concern end context = Operation :: Context . new ( client : client , session : session ) Operation :: Create . new ( selector : operation , db_name : database . name , write_concern : write_concern , session : session , collation : options [ :collation ] || options [ 'collation' ] , ) . execute ( next_primary ( nil , session ) , context : context ) end end
Force the collection to be created in the database.
Force the collection to be created in the database .
# Passing read options to create command causes it to break. # Filter the read options out. # TODO put the list of read options in a class-level constant when # we figure out what the full set of them is. # Converting Ruby spelled time series options to server style. # Note that these are collection options, collation isn't # taken from options passed to the create method.
The result of the command.
The result of the command .
 Result 
opts
:expire_after Number indicating after how many seconds old time-series data should be deleted.
: expire_after Number indicating after how many seconds old time - series data should be deleted .
<not_specific>
opts The options for the create operation.
opts The options for the create operation .
example
Force the collection to be created. collection.create
Force the collection to be created . collection . create
since
None