Skip to main content

Crate mongosh

Crate mongosh 

Source
Expand description

MongoDB Shell Library

This library provides the core functionality for the MongoDB Shell (mongosh) implementation. It can be used as a standalone library to build MongoDB tools and applications.

§Modules

  • cli: Command-line interface and argument parsing
  • config: Configuration management
  • connection: MongoDB connection management
  • error: Error types and handling
  • executor: Command execution engine
  • formatter: Output formatting and display
  • parser: Command and query parsing
  • plugins: Plugin system for extensibility
  • repl: Interactive REPL engine

§Example

use mongosh::{config::Config, connection::ConnectionManager};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::default();
    let mut manager = ConnectionManager::new(
        "mongodb://localhost:27017".to_string(),
        config.connection,
    );

    manager.connect().await?;
    println!("Connected to MongoDB");

    manager.disconnect().await?;
    Ok(())
}

Re-exports§

pub use config::Config;
pub use connection::ConnectionManager;
pub use error::MongoshError;
pub use error::Result;
pub use executor::CommandRouter;
pub use executor::ExecutionResult;
pub use formatter::Formatter;
pub use parser::Command;
pub use parser::Parser;
pub use repl::ReplEngine;

Modules§

cli
Command-line interface for mongosh
config
Configuration management for mongosh
connection
Connection management for MongoDB
error
Error handling module for MongoDB operations.
executor
Command execution engine for mongosh
formatter
Output formatting and colorization for mongosh
parser
Command and query parser for mongosh
repl
REPL (Read-Eval-Print Loop) module root for mongosh

Constants§

VERSION
Library version

Functions§

version
Get library version string