module DynFork::QCommons::Indexes

Overview

Indexing collections.

Extended Modules

Direct including types

Defined in:

dynfork/commons/indexes.cr

Instance Method Summary

Instance Method Detail

def create_index(keys, *, options = NamedTuple.new, commit_quorum : Int32 | String | Nil = nil, max_time_ms : Int64 | Nil = nil, write_concern : Mongo::WriteConcern | Nil = nil, session : Mongo::Session::ClientSession | Nil = nil) : Mongo::Commands::CreateIndexes::Result | Nil #

This is a convenience method for creating a single index.
See: #create_indexes.

NOTE For more details, please check the cryomongo documentation.

Example:

# Create one index without options…
ModelName.create_index(
  keys: {
    "a": 1,
    "b": -1,
  }
)
# or with options (snake_cased)
ModelName.create_index(
  keys: {
    "a": 1,
    "b": -1,
  },
  options: {
    unique: true,
  }
)
# and optionally specify the name.
ModelName.create_index(
  keys: {
    "a": 1,
    "b": -1,
  },
  options: {
    name: "index_name",
  }
)

[View source]
def create_indexes(models : Array, *, commit_quorum : Int32 | String | Nil = nil, max_time_ms : Int64 | Nil = nil, write_concern : Mongo::WriteConcern | Nil = nil, session : Mongo::Session::ClientSession | Nil = nil) : Mongo::Commands::CreateIndexes::Result | Nil #

Creates multiple indexes in the collection.

NOTE For more details, please check the official documentation.

NOTE For more details, please check the cryomongo documentation.

Example:

# Follow the same rules to create multiple indexes with a single method call.
ModelName.create_indexes([
  {
    keys: {a: 1},
  },
  {
    keys: {b: 1}, options: {expire_after_seconds: 3600},
  },
])

[View source]
def drop_index(name : String, *, max_time_ms : Int64 | Nil = nil, write_concern : Mongo::WriteConcern | Nil = nil, session : Mongo::Session::ClientSession | Nil = nil) : Mongo::Commands::Common::BaseResult | Nil #

Drops a single index from the collection by the index name.
See: #drop_indexes.

NOTE For more details, please check the cryomongo documentation.


[View source]
def drop_indexes(*, max_time_ms : Int64 | Nil = nil, write_concern : Mongo::WriteConcern | Nil = nil, session : Mongo::Session::ClientSession | Nil = nil) : Mongo::Commands::Common::BaseResult | Nil #

Drops all indexes in the collection.

NOTE For more details, please check the official documentation.

NOTE For more details, please check the cryomongo documentation.


[View source]
def list_indexes(session : Mongo::Session::ClientSession | Nil = nil) : Mongo::Cursor | Nil #

Gets index information for all indexes in the collection.

NOTE For more details, please check the official documentation.

NOTE For more details, please check the cryomongo documentation.


[View source]