### Configure Meson Setup with Options Source: https://github.com/mongodb/mongo/blob/master/src/third_party/libdwarf/dist/README.md Set build options during the Meson setup phase. This example sets the dwarfexample option and specifies source and build directories. ```bash meson setup -Ddwarfexample=true . /home/davea/dwarf/code ``` -------------------------------- ### Linux Quick Start Build Source: https://github.com/mongodb/mongo/blob/master/docs/building.md Installs Bazel, sets the PATH, and builds the distribution for testing on Linux. ```bash python buildscripts/install_bazel.py export PATH=~/.local/bin:$PATH bazel build install-dist-test bazel-bin/install/bin/mongod --version ``` -------------------------------- ### Setup Virtual Environment and Install Dependencies Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/tools/modularity_check/README.md Set up a virtual environment and install project dependencies using pip. ```sh virtualenv venv (venv) pip install -r requirements.txt ``` -------------------------------- ### Verify Shared Library Installation Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/src/docs/build-posix.dox Example output showing the installed shared library files in /usr/local/lib. This confirms the successful installation of the dynamic library. ```bash file /usr/local/lib/libwiredtiger* /usr/local/lib/libwiredtiger.so.10.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped /usr/local/lib/libwiredtiger.so: symbolic link to `libwiredtiger.so.10.0.1' ``` -------------------------------- ### Example: Profile Queries with Different Engines Source: https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/SCRIPTING_PROFILER_README.md Demonstrates starting the profiler, running queries, stopping it, changing the query engine, and profiling again with a different filename. ```javascript # Start the profiler. let pid = db.adminCommand({sysprofile: 1, filename: "/home/ubuntu/tmp/perf_sbe"}).pid; # Run some queries. for (let i = 0; i < 1000; ++i) { db.search.find({}).toArray(); } # Stop the profiler, and generate profiling data. db.adminCommand({sysprofile: 1, pid: pid}) # Change some settings (e.g. using classic engine). db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"}) # Start profiler again with a different file name. pid = db.adminCommand({sysprofile: 1, filename: "/home/ubuntu/tmp/perf_classic"}).pid; # Run some queries. for (let i = 0; i < 1000; ++i) { db.search.find({}).toArray(); } # Stop the profiler. db.adminCommand({sysprofile: 1, pid: pid}) ``` -------------------------------- ### Example Dotfiles Structure Source: https://github.com/mongodb/mongo/blob/master/docs/devcontainer/customization.md Illustrates a typical directory structure for a dotfiles repository, including configuration files and an installation script. ```bash dotfiles/ ├── .bashrc ├── .gitconfig ├── .vimrc ├── .bash_aliases └── install.sh ``` -------------------------------- ### Create and Open a Database (C) Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/src/docs/examples.dox A fundamental example demonstrating how to create a new WiredTiger database and open an existing one. This is the starting point for any WiredTiger application. ```c #include #include #include #include int main(int argc, char *argv[]) { int ret; WT_CONNECTION *connection; /* Create and open a database */ /* The "create" option ensures the database is created if it doesn't exist */ ret = wiredtiger_open(NULL, NULL, "create", &connection); if (ret != 0) { fprintf(stderr, "Error opening WiredTiger database: %d\n", ret); return 1; } printf("WiredTiger database opened successfully.\n"); /* Close the connection */ ret = connection->close(connection, NULL); if (ret != 0) { fprintf(stderr, "Error closing WiredTiger database: %d\n", ret); return 1; } printf("WiredTiger database closed successfully.\n"); /* Example of opening an existing database (without 'create') */ ret = wiredtiger_open(NULL, NULL, NULL, &connection); if (ret != 0) { fprintf(stderr, "Error opening existing WiredTiger database: %d\n", ret); return 1; } printf("Existing WiredTiger database opened successfully.\n"); connection->close(connection, NULL); return 0; } ``` -------------------------------- ### Setup Python Virtual Environment and Install Dependencies Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/bench/analytics/custom_analysis/README.md This command sequence sets up a Python virtual environment and installs the required packages for running the analysis notebooks. Ensure you have Python 3 installed. ```bash virtualenv -p python3 venv source venv/bin/activate pip3 install jupyter requests matplotlib pymongo==3.12.2 jupyter notebook ``` -------------------------------- ### Example Build and Run Script Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/src/docs/wtperf.dox A shell script demonstrating how to change directory, configure and build WiredTiger, and set up a run directory for wtperf. This is a common setup procedure before running performance tests. ```shell # Change into the WiredTiger directory. cd wiredtiger # Configure and build WiredTiger if not already built. ./configure && make # Remove and re-create the run directory. rm -rf WTPERF_RUN && mkdir WTPERF_RUN ``` -------------------------------- ### Install Dotfiles Script Example Source: https://github.com/mongodb/mongo/blob/master/docs/devcontainer/customization.md A bash script to create symbolic links for configuration files from the dotfiles directory to their standard locations and source the bashrc. ```bash #!/bin/bash ln -sf ~/dotfiles/.bashrc ~/.bashrc ln -sf ~/dotfiles/.gitconfig ~/.gitconfig ln -sf ~/dotfiles/.vimrc ~/.vimrc source ~/.bashrc ``` -------------------------------- ### Install Linux Perf Tools Source: https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/SCRIPTING_PROFILER_README.md Installs the necessary 'perf' command-line tool on Ubuntu 20. This is a one-time setup for a host. ```bash sudo apt install linux-tools-generic ``` -------------------------------- ### Build and Install libdwarf Source: https://github.com/mongodb/mongo/blob/master/src/third_party/libdwarf/dist/READMEwin-msys2.md Build and install libdwarf using Ninja after setting the installation prefix. ```bash ninja install ``` -------------------------------- ### Basic RE2 Installation with Make Source: https://github.com/mongodb/mongo/blob/master/src/third_party/re2/dist/README.md Install RE2 using the provided Makefile. This involves building, testing, benchmarking, and installing the library. ```bash make make test make benchmark make install make testinstall ``` -------------------------------- ### Install WiredTiger Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/src/docs/build-windows.dox Install WiredTiger by building the INSTALL.vcxproj target. ```bash msbuild INSTALL.vcxproj ``` -------------------------------- ### Symbol Count GET Request Example Source: https://github.com/mongodb/mongo/blob/master/src/third_party/gperftools/dist/docs/pprof_remote_servers.html Example response format for a GET request to the /pprof/symbol URL, indicating the number of symbols found in the binary. ```text num_symbols: ### ``` -------------------------------- ### Analyze Explain Output with Sample Data Source: https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/README_explain.md Example demonstrating how to set up sample data and indexes, then run an explain query to analyze performance. ```javascript // Input data for (let i = 1; i <= 100; i++) { db.coll.insertOne({ a: i, b: i % 2 }); } // Indexes [ {a: 1}, {b: 1}, {a: 1, b: 1} ] // Query db.coll.explain().find({a: 1, b: 1}) ``` -------------------------------- ### Get Help for setup-mongot-repro-env Source: https://github.com/mongodb/mongo/blob/master/jstests/with_mongot/e2e/mongot_testing_instructions.md Displays the help message for the setup-mongot-repro-env command, listing all available options. ```bash bazel run db-contrib-tool -- setup-mongot-repro-env --help ``` -------------------------------- ### Fixture Setup with addCleanup Source: https://github.com/mongodb/mongo/blob/master/src/third_party/wiredtiger/test/3rdparty/testtools-2.7.1/doc/for-test-authors.md Demonstrates a common pattern for setting up resources in setUp and scheduling their cleanup using addCleanup. ```python class SomeTest(TestCase): def setUp(self): super(SomeTest, self).setUp() self.server = Server() self.server.setUp() self.addCleanup(self.server.tearDown) ``` -------------------------------- ### Local Installation in Home Directory Source: https://github.com/mongodb/mongo/blob/master/src/third_party/cares/dist/INSTALL.md Example of configuring c-ares for installation directly into the user's home directory, avoiding the need for root privileges. ```bash ./configure --prefix=$HOME make make install ``` -------------------------------- ### FreeBSD Package Installation for Libdwarf Source: https://github.com/mongodb/mongo/blob/master/src/third_party/libdwarf/dist/README.md Installs necessary packages on FreeBSD for building and using libdwarf. It also provides an example of setting CPPFLAGS and LDFLAGS for the compiler to find libraries. ```bash pkg install bash xz python3 gmake liblz4 zstd # example: CPPFLAGS="-I/usr/local/include/" LDFLAGS="-L/usr/local/lib" ./configure ``` -------------------------------- ### Install JSON-C with vcpkg Source: https://github.com/mongodb/mongo/blob/master/src/third_party/json-c/dist/doc/html/index.html Instructions for cloning vcpkg, bootstrapping, integrating, and installing JSON-C. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install vcpkg install json-c ``` -------------------------------- ### Prepare for New Release Source: https://github.com/mongodb/mongo/blob/master/src/third_party/json-c/dist/RELEASE_CHECKLIST.txt Sets up the release version and clones the repository for building. Ensures the build directory is separate from the source tree. ```bash PREV=$(git tag | tail -1) PREV=${PREV#json-c-} PREV=${PREV%-*} release=0.$((${PREV#*.} + 1)) cd ~ git clone https://github.com/json-c/json-c json-c-${release} rm -rf distcheck mkdir distcheck cd distcheck # Note, the build directory *must* be entirely separate from # the source tree for distcheck to work properly. cmake -DCMAKE_BUILD_TYPE=Release ../json-c-${release} make distcheck cd .. ``` -------------------------------- ### Global Section Example Source: https://github.com/mongodb/mongo/blob/master/docs/idl.md Defines the C++ namespace for generated code and includes necessary headers. The `cpp_namespace` must start with `mongo`. ```yaml global: cpp_namespace: "mongo" cpp_includes: - "mongo/idl/idl_test_types.h" ``` -------------------------------- ### Multithreaded Benchmark Setup Source: https://github.com/mongodb/mongo/blob/master/src/third_party/benchmark/dist/README.md Use thread_index to perform setup/teardown only once in multithreaded benchmarks. Ensures all threads reach the start before any begin and all finish before any exit. ```c++ static void BM_MultiThreaded(benchmark::State& state) { if (state.thread_index == 0) { // Setup code here. } for (auto _ : state) { // Run the test as normal. } if (state.thread_index == 0) { // Teardown code here. } } BENCHMARK(BM_MultiThreaded)->Threads(2); ``` -------------------------------- ### GNU Configure/Autotools Build Example Source: https://github.com/mongodb/mongo/blob/master/src/third_party/libdwarf/dist/README.md Demonstrates building libdwarf using the GNU configure script. It shows creating a separate build directory and running configure, make, and make check. ```bash rm -rf /tmp/build mkdir /tmp/build cd /tmp tar xf /libdwarf-0.4.2.tar.xz cd /tmp/build /tmp/libdwarf-0.4.2/configure make make check ``` -------------------------------- ### Use cmake-configure Wrapper Script Source: https://github.com/mongodb/mongo/blob/master/src/third_party/json-c/dist/doc/html/index.html Use the cmake-configure wrapper script for a familiar autoconf-style build process. This example sets the installation prefix and enables threading. ```bash mkdir build cd build ../cmake-configure --prefix=/some/install/path make ``` -------------------------------- ### Configure Always-Installed Dev Container Features Source: https://github.com/mongodb/mongo/blob/master/docs/devcontainer/customization.md Configure VS Code to automatically install specified features in all devcontainers. This example includes git and GitHub CLI. ```json // In your user settings.json { "dev.containers.defaultFeatures": { "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {} } } ``` -------------------------------- ### Configure Autotools Build with Wall and Dwarf Example Source: https://github.com/mongodb/mongo/blob/master/src/third_party/libdwarf/dist/README.md Enable compiler diagnostics with --enable-wall and compile example programs with --enable-dwarfexample during the configure step. ```bash configure --enable-wall --enable-dwarfexample ``` -------------------------------- ### Check Docker Daemon Status Source: https://github.com/mongodb/mongo/blob/master/docs/devcontainer/troubleshooting.md Verify the status and version of your Docker daemon. This can help identify underlying issues with the Docker installation itself when containers fail to start. ```bash docker info docker version ``` -------------------------------- ### Example $sample Rewrite Query and Explain Output Source: https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/timeseries/README.md Demonstrates a user query with a $sample stage and the expected 'winningPlan' from the explain output when the $sample rewrite optimization is applied, favoring option 1 (QUEUED_DATA). ```javascript aggregate([{$sample: {size: 20}}]) ``` ```json "winningPlan" : { "stage" : "TRIAL", "inputStage" : { "stage" : "QUEUED_DATA" } } ``` -------------------------------- ### Build using cmake-configure Wrapper Script Source: https://github.com/mongodb/mongo/blob/master/src/third_party/json-c/dist/README.md Use the `cmake-configure` wrapper script for a familiar autoconf-like build process. This example sets the installation prefix and then builds the library. ```bash mkdir build cd build ../cmake-configure --prefix=/some/install/path make ``` -------------------------------- ### Basic CMake Build for c-ares Source: https://github.com/mongodb/mongo/blob/master/src/third_party/cares/dist/INSTALL.md Build c-ares using CMake on various platforms. This basic example sets the build type to Release and specifies an installation prefix. ```bash cd /path/to/cmake/source mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/cares .. make sudo make install ``` -------------------------------- ### Setup Multi-version Test Suite Source: https://github.com/mongodb/mongo/wiki/Running-Tests-from-Evergreen-Tasks-Locally Use this command to set up a multi-version test suite. Adjust --platform and --architecture for your environment. ```bash [2019/04/23 20:25:52.106] rm -rf /data/install /data/multiversion [2019/04/23 20:25:52.106] $python buildscripts/resmoke.py setup-multiversion [2019/04/23 20:25:52.106] --installDir /data/install [2019/04/23 20:25:52.106] --linkDir /data/multiversion [2019/04/23 20:25:52.107] --edition enterprise [2019/04/23 20:25:52.107] --platform rhel80 [2019/04/23 20:25:52.107] --useLatest 4.0 4.0.5 5.0 ``` -------------------------------- ### Windows MSVC Command Line Build Source: https://github.com/mongodb/mongo/blob/master/src/third_party/cares/dist/INSTALL.md Build c-ares on Windows using the MSVC compiler and NMake Makefiles generator. This example sets the build type and installation prefix. ```bash cd \path\to\cmake\source mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "NMake Makefiles" .. nmake nmake install ``` -------------------------------- ### Create Virtual Environment and Activate Source: https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/benchmark/data_generator/README.md Sets up a Python virtual environment for the data generation tool. Activate it before installing dependencies. ```bash python3 -m venv venv --prompt 'datagen' source venv/bin/activate ``` -------------------------------- ### Shell Script: Basic Test Setup Source: https://github.com/mongodb/mongo/blob/master/src/third_party/zstandard/zstd/tests/cli-tests/README.md A simple setup script that creates three files ('file', 'file0', 'file1') using 'datagen' for testing purposes. ```shell #!/bin/sh # Create some files for testing with datagen > file datagen > file0 datagen > file1 ``` -------------------------------- ### Windows MinGW-w64 Command Line Build via MSYS Source: https://github.com/mongodb/mongo/blob/master/src/third_party/cares/dist/INSTALL.md Build c-ares on Windows using MinGW-w64 and the MSYS Makefiles generator. This example sets the build type and installation prefix. ```bash cd \path\to\cmake\source mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "MSYS Makefiles" .. make make install ``` -------------------------------- ### Shell Script: Dictionary Test Setup Source: https://github.com/mongodb/mongo/blob/master/src/third_party/zstandard/zstd/tests/cli-tests/README.md This setup script copies pre-generated 'files' and 'dicts' directories into the current test case's scratch directory. It's designed to run within a test case's scratch directory, with 'setup_once' operating in the parent directory. ```shell #!/bin/sh # Runs in the test case's scratch directory. # The test suite's scratch directory that # `setup_once` operates in is the parent directory. cp -r ../files ../dicts . ``` -------------------------------- ### Build and Run RNP within a Docker Container Source: https://github.com/mongodb/mongo/blob/master/src/third_party/rnp/dist/docs/develop.adoc This example demonstrates how to start a Docker container, mount the RNP source directory, configure the build with CMake, and then build the project using make. ```console # Start docker, mounting rnp sources directory docker run -it -v $(pwd):/opt/rnp:ro ghcr.io/rnpgp/ci-rnp-fedora-38-amd64 bash # Configure and build rnp, adding additional options like backend selection or enabled sanitizers if needed cd /opt cmake -B build -DBUILD_SHARED_LIBS=On -DCRYPTO_BACKEND=Botan ./rnp cmake --build build --parallel "$(nproc)" ``` -------------------------------- ### Build and Install upb using vcpkg Source: https://github.com/mongodb/mongo/blob/master/src/third_party/protobuf/dist/upb/README.md Steps to build and install upb using the vcpkg dependency manager. This involves cloning vcpkg, bootstrapping, integrating, and installing upb. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install upb ``` -------------------------------- ### Build and Run Abseil Tests with CMake Source: https://github.com/mongodb/mongo/blob/master/src/third_party/abseil-cpp/dist/CMake/README.md Example script to configure, build, and run Abseil tests using CMake. This setup enables testing with Abseil's own tests and automatically downloads Googletest. ```bash cd path/to/abseil-cpp mkdir build cd build cmake -DABSL_BUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON .. make -j ctest ``` -------------------------------- ### Build and Run gRPC Example Source: https://github.com/mongodb/mongo/blob/master/src/third_party/grpc/dist/examples/cpp/compression/README.md Build the gRPC client and server applications using make and run them. ```sh make ./greeter_server ``` ```sh ./greeter_client ``` -------------------------------- ### Get Zstandard Frame Content Size Source: https://github.com/mongodb/mongo/blob/master/src/third_party/zstandard/zstd/doc/zstd_manual.html Determines the decompressed size of a ZSTD encoded frame. The source pointer must point to the start of a valid frame, and srcSize must be sufficient to read the frame header. ```c #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1) #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize); ``` -------------------------------- ### Configure with Standard Options Source: https://github.com/mongodb/mongo/blob/master/src/third_party/icu4c-57.1/readme.html Print available configure options that can be passed to runConfigureICU. This helps in customizing the build process. ```bash ./configure --help ``` -------------------------------- ### Aggregation Pipeline with $lookup and $match (idx 145) Source: https://github.com/mongodb/mongo/blob/master/jstests/query_golden/expected_output/plan_stability_subjoin_cardinality.md This example showcases an aggregation pipeline starting from the 'partsupp' collection, joining with 'supplier', 'nation', and 'region'. It includes $match stages with $or and $nor operators. The query is not eligible for SBE-only plans. ```json {"aggregate":"partsupp","pipeline":[ {"lookup":{"from":"supplier","localField":"ps_suppkey","foreignField":"s_suppkey","pipeline":[ {"match":{"$or":[{"s_acctbal":{"$eq":-686.97}},{"s_nationkey":24}]}},{"match":{"$or":[{"s_nationkey":23},{"s_acctbal":{"$gt":7627.85}}]}}],"as":"supplier"}},{"unwind":"$supplier"},{"lookup":{"from":"nation","localField":"supplier.s_nationkey","foreignField":"n_nationkey","pipeline":[ {"match":{"$nor":[{"n_regionkey":2}]}}],"as":"nation_s"}},{"unwind":"$nation_s"},{"lookup":{"from":"region","localField":"nation_s.n_regionkey","foreignField":"r_regionkey","pipeline":[ {"match":{"$nor":[{"r_regionkey":0}]}}],"as":"region_s"}},{"unwind":"$region_s"},{"match":{"$or":[{"ps_availqty":{"$gte":6104}},{"supplier.s_acctbal":{"$lt":-334.52}}]}}],"cursor":{},"idx":145} ``` -------------------------------- ### Aggregate Query on Supplier with Nested Lookups (idx 68) Source: https://github.com/mongodb/mongo/blob/master/jstests/query_golden/expected_output/plan_stability_subjoin_cardinality.md This example shows an aggregate query starting from the 'supplier' collection, performing nested $lookup operations on 'nation' and 'region' with complex filtering. It's for plan stability testing and not SBE-only. ```json {"aggregate":"supplier","pipeline":[ {" $lookup":{"from":"nation","localField":"s_nationkey","foreignField":"n_nationkey","pipeline":[ {" $match":{"$or":[{"n_regionkey":0},{"n_name":{"$in":["INDIA","IRAN"]}}]}}],"as":"nation_s"}},{" $unwind":"$nation_s"},{" $lookup":{"from":"region","localField":"nation_s.n_regionkey","foreignField":"r_regionkey","pipeline":[ {" $match":{"$nor":[{"r_regionkey":2},{"r_name":"AMERICA"},{"r_regionkey":0}]}}],"as":"region_s"}},{" $unwind":"$region_s"},{" $match":{"$nor":[{"region_s.r_regionkey":3},{"s_name":"Supplier#000000250"}]}}],"cursor":{},"idx":68} ``` -------------------------------- ### Install upb using vcpkg Source: https://github.com/mongodb/mongo/blob/master/src/third_party/grpc/dist/third_party/upb/upb/README.md Build and install upb using the vcpkg dependency manager. This involves cloning the vcpkg repository, bootstrapping it, integrating it with the system, and then installing upb. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install upb ```