Skip to content
Star
478
Star
478

Mongo

This guide shows you how to work with MongoDB locally using Docker Compose, MongoEngine, and Python. This lab demonstrates basic CRUD operations using different execution and validation tools.

  1. Setup Environment:

    Open VS Code in the project folder and execute this command in the Command Palette:

    Terminal window
    > Dev Containers: Reopen in Container
  2. Run the Example:

    Terminal window
    python main.py
  1. main.py:

    • Open: Open main.py.
    • Breakpoints: Set breakpoints in the code.
    • Run: Press F5 to start debugging.
  2. Tests:

    • Open: Open a test file (e.g., tests/test_user.py).
    • Breakpoints: Set breakpoints in the test code.
    • Run: Use the VS Code Testing tab and click the Debug Test icon next to the test you want to debug.
  • All tests: Run the automated script:
    Terminal window
    scripts/run_tests.sh
  • Individually: Use the VS Code Testing tab to run or debug specific test cases.
  1. Enter Shell:
    Terminal window
    scripts/mongosh.sh
  2. Run the following query to see all users:
    db.getSiblingDB('my_db').users.find().pretty()
Terminal window
docker compose down -v