Skip to main content

Crate qm_mongodb

Crate qm_mongodb 

Source
Expand description

MongoDB connection and utilities.

This crate provides MongoDB connection management with automatic user creation, sharding support, and collection management utilities.

§Features

  • Connection Management: Connect to MongoDB with automatic user creation
  • Sharding Support: Enable sharding for collections with hashed shard keys
  • Collection Management: Create collections with indexes and sharding
  • Configuration: Environment-based configuration with prefix support

§Usage

```ignore use qm_mongodb::{DbConfig, DB};

#tokio::main async fn main() -> anyhow::Result<()> { let config = DbConfig::new()?; let db = DB::new(“my-app”, &config).await?; let collection = db.get().collection::(“my_collection”); Ok(()) } ```

§Environment Variables

VariableDescriptionDefault
MONGODB_HOSTMongoDB host127.0.0.1
MONGODB_PORTMongoDB port27017
MONGODB_USERNAMEDatabase username(none)
MONGODB_PASSWORDDatabase password(none)
MONGODB_DATABASEDatabase nametest
MONGODB_ROOT_USERNAMEAdmin username(none)
MONGODB_ROOT_PASSWORDAdmin password(none)
MONGODB_ROOT_DATABASEAdmin databaseadmin
MONGODB_SHARDEDEnable shardingfalse

Modules§

action
Action builder types.
atlas_search
Helpers for building Atlas Search aggregation pipelines. Use one of the constructor functions and chain optional value setters, and then convert to a pipeline stage Document via into_stage.
bson
BSON, short for Binary JSON, is a binary-encoded serialization of JSON-like documents. Like JSON, BSON supports the embedding of documents and arrays within other documents and arrays. BSON also contains extensions that allow representation of data types that are not part of the JSON spec. For example, BSON has a datetime type and a binary data type.
change_stream
Contains the functionality for change streams.
error
Contains the Error and Result types that mongodb uses.
event
Contains the events and functionality for monitoring internal Client behavior.
gridfs
Contains the functionality for GridFS operations.
options
Contains all of the types needed to specify options to MongoDB operations.
raw_batch_cursor
Raw batch cursor API for zero-copy document processing.
results
Contains the types of results returned by CRUD operations.

Macros§

db
Macro to implement AsRefqm::mongodb::DB for a storage type.

Structs§

Client
This is the main entry point for the API. A Client is used to connect to a MongoDB cluster. By default, it will monitor the topology of the cluster, keeping track of any changes, such as servers being added or removed.
ClientSession
A MongoDB client session. This struct represents a logical session used for ordering sequential operations. To create a ClientSession, call start_session on a Client.
ClusterTime
Struct modeling a cluster time reported by the server.
Collection
Collection is the client-side abstraction of a MongoDB Collection. It can be used to perform collection-level operations such as CRUD operations. A Collection can be obtained through a Database by calling either Database::collection or Database::collection_with_options.
Cursor
A Cursor streams the result of a query. When a query is made, the returned Cursor will contain the first batch of results from the server; the individual results will then be returned as the Cursor is iterated. When the batch is exhausted and if there are more results, the Cursor will fetch the next batch of documents, and so forth until the results are exhausted. Note that because of this batching, additional network I/O may occur on any given call to next. Because of this, a Cursor iterates over Result<T> items rather than simply T items.
DB
MongoDB database connection wrapper.
Database
Database is the client-side abstraction of a MongoDB database. It can be used to perform database-level operations or to obtain handles to specific collections within the database. A Database can only be obtained through a Client by calling either Client::database or Client::database_with_options.
DbConfig
MongoDB configuration.
IndexModel
Specifies the fields and options for an index. For more information, see the documentation.
Namespace
A struct modeling the canonical name for a collection in MongoDB.
SearchIndexModel
Specifies the options for a search index.
ServerInfo
A description of the most up-to-date information known about a server. Further details can be found in the Server Discovery and Monitoring specification.
SessionCursor
A SessionCursor is a cursor that was created with a ClientSession that must be iterated using one. To iterate, use SessionCursor::next or retrieve a SessionCursorStream using SessionCursor::stream:
SessionCursorStream
A type that implements Stream which can be used to stream the results of a SessionCursor. Returned from SessionCursor::stream.

Enums§

SearchIndexType
Specifies the type of search index.
ServerType
Enum representing the possible types of servers that the driver can connect to.
TopologyType
The possible types for a topology.

Functions§

insert_always_opts
Create options for upsert (insert or update) operations.
parse_vec
Parse a MongoDB cursor into a vector of deserialized documents.

Type Aliases§

BoxFuture
A boxed future.