### Bref PHP Setup and Configuration (Bash) Source: https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda Commands to set up a new Bref PHP project, install dependencies including MongoDB, and initialize the serverless configuration. ```bash mkdir bref-mongodb-app && cd bref-mongodb-app composer init composer require bref/bref bref/extra-php-extensions mongodb/mongodb vendor/bin/bref init ``` -------------------------------- ### Run Atlas Setup Command Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started Initiates the Atlas setup process, which includes account creation, authentication, and database setup. ```bash atlas setup ``` -------------------------------- ### Select Setup Method (Interactive Default) Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Choose 'default - With default settings' during interactive setup for a straightforward local MongoDB database configuration. ```sh ? How do you want to setup your local MongoDB database? [Use arrows to move, type to filter] > default - With default settings custom - With custom settings cancel - Cancel set up ``` -------------------------------- ### Select Setup Method (Interactive Custom) Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Choose 'custom - With custom settings' during interactive setup to configure your local MongoDB database with custom parameters. ```sh ? How do you want to setup your local MongoDB database? [Use arrows to move, type to filter] default - With default settings > custom - With custom settings cancel - Cancel set up ``` -------------------------------- ### Example: Create Index for Customers Collection Source: https://www.mongodb.com/docs/atlas/atlas-ui/collections This example demonstrates how to create an index on the 'username' field for the 'sample_analytics.customers' collection. ```javascript db.sample_analytics.createIndex( { "username": 1 } ) ``` -------------------------------- ### Example: Shard Customers Collection Source: https://www.mongodb.com/docs/atlas/atlas-ui/collections This example shows how to shard the 'sample_analytics.customers' collection using 'username' as the shard key. ```javascript sh.shardCollection("sample_analytics.customers", { "username" : 1 } ) ``` -------------------------------- ### Setup Local MongoDB with Sample Data (Interactive Default) Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Use the `--loadSampleData true` flag during interactive setup to load MongoDB sample data. ```sh atlas local setup --loadSampleData true ``` -------------------------------- ### Setup Local MongoDB (Non-Interactive) Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Run the `atlas local setup` command with options for a non-interactive deployment of a local MongoDB instance. ```sh atlas local setup myLocalRs1 --force ``` -------------------------------- ### Clone Azure Atlas Examples Source: https://www.mongodb.com/docs/atlas/terraform-modules-landing-zone Clone the Atlas Examples repository and navigate to the Azure complete module directory. ```sh git clone https://github.com/terraform-mongodbatlas-modules/atlas-examples.git cd atlas-examples/azure/atlas-azure-module-complete ``` -------------------------------- ### Example Connection Secret Source: https://www.mongodb.com/docs/atlas/operator/current/ak8so-quick-start This is an example of the connection details you might retrieve. Your actual connection strings will differ. ```json { "connectionStringStandard": "mongodb://theuser:P%40%40sword%25@test-cluster-shard-00-00.peqtm.mongodb.net:27017,test-cluster-shard-00-01.peqtm.mongodb.net:27017,test-cluster-shard-00-02.peqtm.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-pk82fl-shard-0", "connectionStringStandardSrv": "mongodb+srv://theuser:P%40%40sword%25@test-cluster.peqtm.mongodb.net", "password": "P@@sword%", "username": "theuser" } ``` -------------------------------- ### Example SRV Connection String Source: https://www.mongodb.com/docs/atlas/connect-to-database-deployment This is an example of a SRV connection string returned by the Atlas CLI. ```text mongodb+srv://mycluster.abcd1.mongodb.net ``` -------------------------------- ### Install Necessary Libraries Source: https://www.mongodb.com/docs/atlas/architecture/current/partner-showcase/xlrt Installs the required Python libraries for MongoDB interaction, LangChain integration, and Ollama for LLM requests. ```python pip install --quiet --upgrade pymongo langchain_mongodb langchain_ollama ``` -------------------------------- ### Clone AWS Atlas Examples Source: https://www.mongodb.com/docs/atlas/terraform-modules-landing-zone Clone the Atlas Examples repository and navigate to the AWS complete module directory. ```sh git clone https://github.com/terraform-mongodbatlas-modules/atlas-examples.git cd atlas-examples/aws/atlas-aws-module-complete ``` -------------------------------- ### Atlas Setup Deployment Output Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started Displays the output after running `atlas setup`, including cluster deployment status and database authentication details. ```sh We are deploying Cluster9876543... Please store your database authentication access details in a secure location. Database User Username: Cluster9876543 Database User Password: abcdef12345 Creating your cluster... [Its safe to 'Ctrl + C'] ``` -------------------------------- ### Install MongoDB Atlas CLI and Mongosh using Apt Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli Installs both the MongoDB Atlas CLI and mongosh using the apt package manager. ```shell sudo apt-get install -y mongodb-atlas ``` -------------------------------- ### Install Atlas Operator (Specific Namespaces) Source: https://www.mongodb.com/docs/atlas/operator/current/ak8so-quick-start-helm Install the Atlas Kubernetes Operator to watch only a specified set of namespaces. This example configures the operator to watch the 'atlas-operator' namespace. ```sh helm install atlas-operator --namespace=atlas-operator --set watchNamespaces=atlas-operator --create-namespace mongodb/mongodb-atlas-operator ``` -------------------------------- ### Atlas Project and Deployment Examples Source: https://www.mongodb.com/docs/atlas/operator/current/atlasdatabaseuser-custom-resource Defines an Atlas project and two Atlas deployments (AWS and GCP). This serves as a foundational setup for creating database users within a specific project. ```yaml apiVersion: atlas.mongodb.com/v1 kind: AtlasProject metadata: name: my-project spec: name: p1 projectIpAccessList: - ipAddress: "192.0.2.15" comment: "IP address for Application Server A" apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-aws-cluster spec: name: aws-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: AWS regionName: US_EAST_1 apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-gcp-cluster spec: name: gcp-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: GCP regionName: EASTERN_US ``` -------------------------------- ### List Organizations Source: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2 This example demonstrates how to retrieve a list of organizations associated with your Atlas account using the Administration API. It includes steps for generating an OAuth2 access token and then using that token to make the GET request to the organizations endpoint. ```APIDOC ## GET /api/atlas/v2/orgs ### Description Retrieves a list of all organizations that the authenticated user can access. ### Method GET ### Endpoint https://cloud.mongodb.com/api/atlas/v2/orgs ### Parameters #### Query Parameters - **pretty** (boolean) - Optional - If true, returns the response in a pretty-printed format. ### Request Example ```bash ACCESS_TOKEN=$(curl -fsS --request POST https://cloud.mongodb.com/api/oauth/token \ --header "Authorization: Basic $(printf '%s' "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d '\n')" \ --header "Content-Type: application/x-www-form-urlencoded" \ --header "Accept: application/json" \ --data "grant_type=client_credentials" | jq -r '.access_token') curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header "Accept: application/vnd.atlas.2025-03-12+json" \ -X GET "https://cloud.mongodb.com/api/atlas/v2/orgs?pretty=true" ``` ### Response #### Success Response (200) - **results** (array) - A list of organization objects. - **id** (string) - The unique identifier for the organization. - **name** (string) - The name of the organization. #### Response Example ```json { "results": [ { "id": "60b8d295c3f40c0011a4b123", "name": "Example Organization" } ] } ``` ``` -------------------------------- ### Run Sample Application Source: https://www.mongodb.com/docs/atlas/tutorial/insert-data-into-your-cluster Execute the Python script to insert data into your cluster. Ensure you have the necessary dependencies installed. ```shell python insert-data.py ``` -------------------------------- ### Install Atlas CLI only using Yum Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli If you do not want to install mongosh, use this alternative yum command to install only the Atlas CLI. ```sh sudo yum install -y mongodb-atlas-cli ``` -------------------------------- ### Confirm Free Database Setup Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started Confirms the creation of a free, forever-use M0 shared-tier cluster with default settings. ```bash Do you want to set up your first free database in Atlas with default settings? It's free forever! Y ``` -------------------------------- ### Verify Atlas CLI Installation Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli After installation, run this command to verify that the Atlas CLI is installed correctly and to see available commands. ```sh atlas ``` -------------------------------- ### Install gnupg and curl using Apt Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli Before installing the Atlas CLI using Apt, ensure that gnupg and curl are installed on your system. ```sh sudo apt-get install gnupg curl ``` -------------------------------- ### Example Prompt for Migrating Existing Project Source: https://www.mongodb.com/docs/atlas/ai-cluster-assistant Use this prompt to inquire about cluster configuration for migrating an existing project with a specific data size and geographic requirement. ```text I ’m looking to migrate an existing project to Atlas. We currently have 100GB of data that we need to move over. The project is currently deployed in Europe and we want to maintain that. How should I configure my cluster? ``` -------------------------------- ### Start a Local Atlas Deployment Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Start a previously paused or stopped local Atlas deployment. The CLI will prompt you to select the deployment to start. ```sh atlas local start ``` -------------------------------- ### Select Deployment Type (Interactive Default) Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local During interactive setup, select 'local - Local Database' to deploy a local MongoDB instance. ```sh ? What would you like to deploy? [Use arrows to move, type to filter, ? for more help] > local - Local Database atlas - Atlas Database ``` -------------------------------- ### Install Atlas CLI and mongosh using Homebrew Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli Use this command to install both the Atlas CLI and mongosh via Homebrew. You cannot install the Atlas CLI alone using Homebrew. ```sh brew install mongodb-atlas ``` -------------------------------- ### Replica Set Standard Connection String Example Source: https://www.mongodb.com/docs/atlas/import/c2c-pull-live-migration Example of a standard connection string for a replica set cluster used for live migration. Ensure the database user has the necessary roles and actions. ```none mongodb://:@replica-shard-00-00.AA000.example.net:27017,replica-shard-00-01.AA000.example.net:27017,replica-shard-00-02.AA000.example.net:27017/?tls=true&replicaSet=atlas-example-shard-0&authSource=admin&appName=replica ``` -------------------------------- ### Install mongosh on Debian/Ubuntu Source: https://www.mongodb.com/docs/atlas/mongo-shell-connection Use dpkg to install the mongosh package on Debian or Ubuntu-based systems. ```sh sudo dpkg -i mongodb-mongosh_.deb ``` -------------------------------- ### Run C# Application Source: https://www.mongodb.com/docs/atlas/tutorial/insert-data-into-your-cluster Command to execute the C# sample application. Ensure you have the .NET SDK installed. ```shell dotnet run Program.cs ``` -------------------------------- ### Install Atlas CLI with Chocolatey Source: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli Use this command to install or upgrade the Atlas CLI using Chocolatey. ```powershell choco upgrade mongodb-atlas ``` -------------------------------- ### Copy Terraform Variables Example Source: https://www.mongodb.com/docs/atlas/terraform-modules-landing-zone Copy the example terraform.tfvars file to begin configuring your deployment variables. ```sh cp terraform.tfvars.example terraform.tfvars ``` -------------------------------- ### Create Terraform Files Source: https://www.mongodb.com/docs/atlas/terraform Create the necessary Terraform configuration files. ```bash touch main.tf provider.tf variables.tf versions.tf ``` -------------------------------- ### Sample Document Output Source: https://www.mongodb.com/docs/atlas/tutorial/insert-data-into-your-cluster This is an example of a document successfully inserted into the cluster. Note that the _id field is system-generated. ```json Document found: { '_id': ObjectId('65c2a8188388383b00a85b1f'), 'name': { 'first': 'Alan', 'last': 'Turing' }, 'birth': datetime.datetime(1912, 6, 23, 0, 0), 'death': datetime.datetime(1954, 6, 7, 0, 0), 'contribs': [ 'Turing machine', 'Turing test', 'Turingery' ], 'views': 1250000 } ``` -------------------------------- ### Install mongosh with Homebrew Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Use Homebrew to install the MongoDB Shell (mongosh) on macOS. This is an optional but recommended tool. ```shell brew install mongosh ``` -------------------------------- ### Discussing Budget Constraints with AI Cluster Assistant Source: https://www.mongodb.com/docs/atlas/ai-cluster-assistant Use this prompt to ask the AI Cluster Assistant for a cost-effective cluster setup. It will suggest a configuration to meet your budget. ```text My cluster costs more than expected. Is there a setup that keeps us under $500/mo? ``` ```text To keep monthly costs under $500, I recommend switching to an M30 tier. This provides reliable performance for standard production workloads at around $394/month on AWS, plus some buffer for backups and storage. Here’s how I’ll configure it: - Instance size: M30 (entry-level dedicated, good for most production apps) - Region: N. Virginia (US_EAST_1) (stays consistent with your existing clusters) - Disk size: 40GB (default for M30, suitable for moderate workloads) - No additional IOPS or premium storage (keeps costs down) - No analytics/search node or advanced add-ons Let’s proceed with this cost-effective configuration. Before finalizing, can you clarify: - Is this cluster for production, staging, or development? - What’s your estimated data volume (just rough amount of GB needed)? - Any specific performance requirements (high writes, reads, etc.)? I’ll now suggest the configuration for you. ``` -------------------------------- ### Clone GCP Atlas Examples Source: https://www.mongodb.com/docs/atlas/terraform-modules-landing-zone Clone the Atlas Examples repository and navigate to the GCP complete module directory. ```sh git clone https://github.com/terraform-mongodbatlas-modules/atlas-examples.git cd atlas-examples/gcp/atlas-gcp-module-complete ``` -------------------------------- ### Set up Local Atlas Deployment Source: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local Initializes a local MongoDB Atlas deployment. Use the --initdb flag to start with custom data and indexes. ```sh atlas local setup ``` ```sh atlas local setup --initdb {folder} ``` -------------------------------- ### Create Project using Basic Auth Source: https://www.mongodb.com/docs/atlas/configure-api-access This POST request creates a new project using basic authentication. Provide your public and private keys, project name, and organization ID. ```sh curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Content-Type: application/json" \ --header "Accept: application/vnd.atlas.2024-08-05+json" \ --include \ --request POST "https://cloud.mongodb.com/api/atlas/v2/groups" \ --data ' { "name": "MyProject", "orgId": "5a0a1e7e0f2912c554080adc" }' ``` -------------------------------- ### Construct Prompt with Context and Query Source: https://www.mongodb.com/docs/atlas/architecture/current/partner-showcase/xlrt Combines retrieved context with a user query using a LangChain prompt template and an LLM served by Ollama. ```python from langchain_ollama import ChatOllama from langchain.prompts import PromptTemplate # Set up Ollama as the LLM with your model of choice llm = ChatOllama(model="") # Define a prompt template template = """ You are an AI financial analyst. Analyze the following data and provide insights: {context} User Query: {query} """ prompt = PromptTemplate( input_variables= ["context", "query"], template=template ) chain = prompt | llm response = chain.invoke({"context": context, "query": Query}) print("Generated Insights:\n", response) ``` -------------------------------- ### Optimized SRV Connection String Example Source: https://www.mongodb.com/docs/atlas/reference/faq/connection-changes An example of an optimized SRV connection string, identifiable by the addition of 'lb'. ```mongodb mongodb+SRV://User1:P@ssword@cluster0-pl-0-lb.oq123.mongodb-dev.net/ ``` -------------------------------- ### BSON Documents Example Source: https://www.mongodb.com/docs/atlas/data-federation/supported-unsupported/pipeline/out Illustrates sample BSON documents that will be written to Parquet format. ```json { "clientId": 102, "phoneNumbers": ["123-4567", "234-5678"], "clientInfo": { "name": "Taylor", "occupation": "teacher" } } { "clientId": "237", "phoneNumbers" ["345-6789"] "clientInfo": { "name": "Jordan" } } ``` -------------------------------- ### Terraform Initialization and Deployment Commands Source: https://www.mongodb.com/docs/atlas/terraform-modules-landing-zone Standard Terraform commands to initialize the working directory, preview changes, and apply the infrastructure. Use `-var-file` to specify your variable definitions. ```sh terraform init terraform plan -var-file terraform.tfvars terraform apply -var-file terraform.tfvars ```