|
| 1 | +# Project Description |
| 2 | + |
| 3 | +This is the Ruby driver for the MongoDB database. It provides a Ruby interface for connecting to MongoDB, performing CRUD operations, and managing database connections. The API is standardized across all MongoDB drivers, via the specifications defined in the MongoDB Specifications repository: https://github.com/mongodb/specifications. The driver targets Ruby 2.7+. Do not use syntax or stdlib features unavailable in Ruby 2.7. |
| 4 | + |
| 5 | +# Project Structure |
| 6 | + |
| 7 | +The project is organized into the following directories: |
| 8 | + |
| 9 | +- `lib/`: the main codebase |
| 10 | +- `spec/`: RSpec tests for the project, and shared test data |
| 11 | +- `bin/`: executable scripts |
| 12 | +- `examples/`: example usage of the library |
| 13 | +- `gemfiles/`: Gemfile files for different usage scenarios (primarily testing, aside from `standard.rb` which is used for development and production) |
| 14 | +- `profile/`: profiling scripts and results |
| 15 | + |
| 16 | + |
| 17 | +# Development Workflow |
| 18 | + |
| 19 | +## Running tests |
| 20 | + |
| 21 | +Tests require a running MongoDB instance. Set the URI via the `MONGODB_URI` environment variable: |
| 22 | + |
| 23 | +``` |
| 24 | +MONGODB_URI="mongodb://localhost:27017,localhost:27018,localhost:27019/" bundle exec rspec spec/path/to/spec.rb |
| 25 | +``` |
| 26 | + |
| 27 | +A replica set is typically available locally at `localhost:27017,27018,27019`. |
| 28 | + |
| 29 | +## Linting |
| 30 | + |
| 31 | +Run RuboCop after making changes, and always before committing: |
| 32 | + |
| 33 | +``` |
| 34 | +bundle exec rubocop lib/mongo/changed_file.rb spec/mongo/changed_file_spec.rb |
| 35 | +``` |
| 36 | + |
| 37 | +Pass the specific files you modified. |
| 38 | + |
| 39 | +RuboCop is configured with performance, rake, and rspec plugins (`.rubocop.yml`). |
| 40 | + |
| 41 | +## Commit convention |
| 42 | + |
| 43 | +Prefix commit messages with the JIRA ticket: `RUBY-#### Short description`. The ticket number is typically in the branch name (e.g., branch `3795-foo` means `RUBY-3795`). |
| 44 | + |
| 45 | +## Prose style |
| 46 | + |
| 47 | +When writing prose — commit messages, code comments, documentation — be concise, write as a human would, avoid overly complicated sentences, and use no emojis. |
| 48 | + |
| 49 | +## Definition of done |
| 50 | + |
| 51 | +Always run the relevant spec file(s) against the local cluster before considering a task complete. Running tests is not optional. "Relevant" means: the spec file for each class you changed, plus any integration specs in `spec/integration/` that exercise the affected feature. If MongoDB is not reachable, report this to the user rather than trying to work around it. |
| 52 | + |
| 53 | +## Thread and fiber safety |
| 54 | + |
| 55 | +This driver runs in multi-threaded and multi-fiber environments. When writing or modifying code that touches connection pools, server monitors, or any shared state, always consider concurrent access. Use existing synchronization primitives in the codebase rather than introducing new ones. |
| 56 | + |
| 57 | +## Spec fixtures |
| 58 | + |
| 59 | +Unified test format YAML fixtures live in `spec/spec_tests/data/<suite_name>/`. To add new fixtures, copy YAML files from `specifications/source/<spec-name>/tests/unified/` into that directory. The runner loads all `*.yml` files automatically — no runner changes needed. |
| 60 | + |
| 61 | +Do not write Ruby specs that duplicate behavior already covered by YAML spec tests. New Ruby specs should cover behavior that cannot be expressed in the unified test format. |
| 62 | + |
| 63 | + |
| 64 | +# Code Reviews |
| 65 | + |
| 66 | +See [.github/code-review.md](.github/code-review.md) for code review guidelines. |
0 commit comments