MongoDB Compass Documentation

repository·main·Indexed 23 days ago

https://github.com/mongodb-js/compass

Source code, plugins, and build tooling for MongoDB Compass, the official MongoDB graphical user interface. This monorepo includes shared configurations for ESLint, Mocha, Prettier, and TypeScript, as well as specialized packages such as bson-transpilers for converting BSON code between languages, mongodb-collection-model, and the @mongodb-js/compass-aggregations plugin for building aggregation pipelines.

Tokens
127.9K
Snippets
160
Records
742
Agent score
81%

What's inside MongoDB Compass

  1. Overview of MongoDB Compass Monorepo packages

    main

    The MongoDB Compass Monorepo contains the source code and build tooling for MongoDB Compass. The repository is organized into several categories of packages:

    Core Application

    • mongodb-compass: The primary MongoDB GUI application.

    Compass Plugins

    These packages extend the functionality of the Compass GUI, including features like:

    • Aggregation Pipeline Builder: @mongodb-js/compass-aggregations
    • CRUD Operations: @mongodb-js/compass-crud
    • Database & Collection Management: @mongodb-js/compass-databases-collections
    • Explain Plan: @mongodb-js/compass-explain-plan
    • Schema Tab: @mongodb-js/compass-schema
    • Shell: @mongodb-js/compass-shell
    • Indexes: @mongodb-js/compass-indexes
    • Import/Export: @mongodb-js/compass-import-export
    • Find in Page: @mongodb-js/compass-find-in-page

    Shared Libraries and Build Tools

    Internal utilities and services used across the monorepo, such as:

    • Atlas Service: @mongodb-js/atlas-service (handles Atlas sign-in and API requests)
    • UI Components: @mongodb-js/compass-components (React components)
    • Editor: @mongodb-js/compass-editor (CodeMirror-based editor)
    • Connection Management: @mongodb-js/compass-connections and @mongodb-js/connection-form
    • Testing: @mongodb-js/compass-smoke-tests and compass-e2e-tests
    • Build Tooling: hadron-build (tooling for Hadron apps like Compass)

    Shared Configuration Files

    Standardized configurations for development:

    • Linting: @mongodb-js/eslint-config-compass and @mongodb-js/eslint-plugin-compass
    • Testing: @mongodb-js/mocha-config-compass and @mongodb-js/testing-library-compass
    • Formatting: @mongodb-js/prettier-config-compass
    • TypeScript: @mongodb-js/tsconfig-compass
    • Bundling: @mongodb-js/webpack-config-compass
  2. Overview of @mongodb-js/compass-components

    main

    The @mongodb-js/compass-components package serves as the central repository for all foundational components and hooks used to build parts of MongoDB Compass.

    By consolidating leafygreen dependencies and core UI components into this single package, the project achieves two main goals:

    1. Dependency Management: It prevents technical issues caused by having multiple versions of the same LeafyGreen packages running in the application simultaneously.
    2. UI Consistency: It ensures that UI updates are applied consistently across the entire Compass application.
  3. Overview of Compass Schema Validation plugin

    main
    The compass-schema-validation plugin extends MongoDB Compass by providing advanced schema validation capabilities. It allows users to manage complex validation rules using JSON Schema in addition to standard MongoDB Query Language (MQL) based simple validation. This plugin is more flexible than standard document validation for creating intricate rules.
  4. Overview of Compass Tracking Plan categories

    main
    The Compass Tracking Plan defines the telemetry events captured within the application. Events are organized into functional categories such as Aggregation Builder, Assistant, Connection, Data Modeling, Find Queries, Gen AI, Indexes, Schema, and Search Indexes. This plan ensures consistent tracking of user interactions, errors, and feature usage across the Compass ecosystem.
  5. Use the Compass Databases and Collections Plugin

    main

    The Compass Databases and Collections Plugin extends MongoDB Compass by providing essential UI components for managing data structures. It provides the following features:

    • Collection Management: Includes a Collection List Table and modals for creating or dropping collections.
    • Database Management: Includes a Database List Table and modals for creating or dropping databases.
    • Collation Support: Provides fields for configuring Collation settings.
  6. Convert MongoDB SBE explain output to 4.4 format

    main
    The mongodb-explain-compat package provides functionality to convert MongoDB SBE (Small Binary Encoding) explain output into the format used by MongoDB version 4.4. While the converted output may not be an exact match, it is designed to be close enough for practical use and analysis in tools expecting the 4.4 schema.
  7. How hadron-ipc works: Main vs Renderer processes

    main

    hadron-ipc provides a simplified wrapper around Electron's Inter-Process Communication (IPC) events. It distinguishes between two environments:

    1. Main Process: Responsible for managing the application lifecycle and communicating to renderer processes using broadcast or responding to renderer requests using respondTo.
    2. Renderer Process: Responsible for the UI. It communicates to the main process using call or listens for broadcasts from the main process using on.

    Common patterns include a renderer calling a method (ipc.call), the main process responding to that call (ipc.respondTo), and the main process subsequently notifying all renderers of a state change (ipc.broadcast).

    const ipc = require('hadron-ipc');
    const AppRegistry = require('@mongodb-js/compass-app-registry');
    
    const globalAppRegistry = new AppRegistry();
    
    // 1. Renderer process initiates a call
    ipc.call('compass:loading:change-status', { status: 'loading preferences' });
    
    // 2. Main process responds to the call and broadcasts the update
    ipc.respondTo('app:loading:change-status', (evt, meta) => {
      ipc.broadcast('app:loading:change-status', meta);
    });
    
    // 3. Renderer processes listen for the broadcast
    ipc.on('app:loading:change-status', (evt, meta) => {
      globalAppRegistry.emit('app:loading:change-status', meta);
    });
  8. Features of Compass Schema Validation

    main

    The plugin provides the following capabilities for managing collection validation:

    • Rule Management: Show, create, edit, and delete schema validation rules.
    • Syntax Support: Use both MQL and JSON schema syntax. It accepts any query syntax, including but not limited to $jsonSchema.
    • Developer Experience: Field and keyword autocompletion, and syntactic validation to enforce correct syntax.
    • Validation Configuration: View and modify validationLevel (strict, moderate, or off) and validationAction (error or warn).
    • Data Preview: View previews of sample documents in a collection that either match or do not match the current validation rules.