### Start MongoDB Container Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Use this command to start a MongoDB container with test data. Ensure you are in the tests directory. ```bash python mongo_test_helper.py start ``` -------------------------------- ### Install PyMongoSQL from source Source: https://github.com/passren/pymongosql/blob/main/README.md Install PyMongoSQL directly from its source code repository for development or the latest features. This involves cloning the repository and performing an editable installation. ```bash git clone https://github.com/passren/PyMongoSQL.git cd PyMongoSQL pip install -e . ``` -------------------------------- ### Install PyMongoSQL using pip Source: https://github.com/passren/pymongosql/blob/main/README.md Install the PyMongoSQL library using pip for easy integration into your Python projects. ```bash pip install pymongosql ``` -------------------------------- ### Setup or Reset Test Data Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Execute this command to set up or reset the test data within the MongoDB instance. This ensures a clean state for tests. ```bash python mongo_test_helper.py setup ``` -------------------------------- ### Start Docker Compose for Tests Source: https://github.com/passren/pymongosql/blob/main/tests/README.md This command starts the services defined in docker-compose.test.yml in detached mode. Ensure you are in the tests directory. ```bash docker-compose -f docker-compose.test.yml up -d ``` -------------------------------- ### Inspect MongoDB Query Plan with EXPLAIN Source: https://github.com/passren/pymongosql/blob/main/README.md Prefix SELECT statements with EXPLAIN to get the MongoDB query plan. The results are flattened into 'stage' and 'details' columns. ```python # Default verbosity: queryPlanner cursor.execute("EXPLAIN SELECT * FROM users WHERE age > 21") for stage, details in cursor.fetchall(): print(stage, details) # Request executionStats (actual timing, docs/keys examined) or allPlansExecution cursor.execute("EXPLAIN (verbosity executionStats) SELECT * FROM users WHERE age > 21") ``` -------------------------------- ### Configure Retry on Transient System Errors Source: https://github.com/passren/pymongosql/blob/main/README.md Configure PyMongoSQL to automatically retry transient MongoDB errors using the Tenacity library. Install with `pip install pymongosql[retry]`. ```python connection = connect( host="mongodb://localhost:27017/database", retry_enabled=False, # default: False retry_attempts=3, # default: 3 retry_wait_min=0.1, # default: 0.1 seconds retry_wait_max=1.0, # default: 1.0 seconds ) ``` -------------------------------- ### Run Quick Unit Tests Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Execute a subset of unit tests for connection, cursor, and result set classes. This command requires MongoDB to be running. ```bash cd .. python -m pytest tests/test_connection.py tests/test_cursor.py tests/test_result_set.py -v ``` -------------------------------- ### Basic PyMongoSQL Usage Source: https://github.com/passren/pymongosql/blob/main/README.md Connect to a MongoDB instance and execute a simple SQL query to fetch data. Ensure you have a MongoDB server running and a database named 'database' with a 'users' collection. ```python from pymongosql import connect # Connect to MongoDB connection = connect( host="mongodb://localhost:27017", database="database" ) cursor = connection.cursor() cursor.execute('SELECT name, email FROM users WHERE age > 25') print(cursor.fetchall()) ``` -------------------------------- ### Run All Tests Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Execute all tests within the tests directory, including unit and integration tests. This command requires both MongoDB and Docker to be running. ```bash cd .. python -m pytest tests/ -v ``` -------------------------------- ### Query with Named Parameters (:name) Source: https://github.com/passren/pymongosql/blob/main/README.md Execute SQL queries using named parameters with the ':name' placeholder. This approach enhances query readability, especially for complex queries. ```python from pymongosql import connect connection = connect(host="mongodb://localhost:27017/database") cursor = connection.cursor() cursor.execute( 'SELECT name, email FROM users WHERE age > :age AND status = :status', {'age': 25, 'status': 'active'} ) ``` -------------------------------- ### Create MongoDB View with SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Define MongoDB views using SQL CREATE VIEW syntax. The pipeline must be a valid JSON array string enclosed in single quotes. ```python import json # Create a view with a filter pipeline pipeline = json.dumps([{"$": "match", "active": True}]) cursor.execute(f"CREATE VIEW active_users ON users AS '{pipeline}'") # Create a view with a $lookup (join) pipeline pipeline = json.dumps([ {"$": "lookup", "from": "orders", "localField": "_id", "foreignField": "user_id", "as": "user_orders"} ]) cursor.execute(f"CREATE VIEW users_with_orders ON users AS '{pipeline}'") # Query the view like any collection cursor.execute("SELECT * FROM active_users") ``` -------------------------------- ### Connect to MongoDB using Connection String Source: https://github.com/passren/pymongosql/blob/main/README.md Connect to MongoDB using a full connection string, including authentication credentials. This method is useful for connecting to remote or secured MongoDB instances. ```python from pymongosql import connect # Connect with authentication connection = connect( host="mongodb://username:password@localhost:27017/database?authSource=admin" ) cursor = connection.cursor() cursor.execute('SELECT * FROM products WHERE category = ?', ['Electronics']) for row in cursor: print(row) ``` -------------------------------- ### PyMongoSQL Cursor (Tuple Results) Source: https://github.com/passren/pymongosql/blob/main/README.md Demonstrates the default cursor behavior, returning rows as tuples. Access data using numerical indices. ```python cursor = connection.cursor() cursor.execute('SELECT name, email FROM users') row = cursor.fetchone() print(row[0]) # Access by index ``` -------------------------------- ### Run Integration Tests Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Execute integration tests that interact with a real MongoDB instance, likely managed by TestContainers. This requires Docker to be running. ```bash cd .. python -m pytest tests/test_integration_mongodb.py -v ``` -------------------------------- ### Parameterized INSERT (PartiQL-Style) Source: https://github.com/passren/pymongosql/blob/main/README.md Perform parameterized inserts for single documents using PartiQL-style object literals and positional (?) placeholders. This helps prevent injection vulnerabilities. ```python # Positional parameters using ? placeholders cursor.execute( "INSERT INTO Music {'title': '?', 'artist': '?', 'year': '?'}", ["Song D", "Diana", 2020] ) ``` -------------------------------- ### Query with Positional Parameters (?) Source: https://github.com/passren/pymongosql/blob/main/README.md Execute SQL queries with positional parameters using the '?' placeholder. This method is secure against SQL injection by properly escaping values. ```python from pymongosql import connect connection = connect(host="mongodb://localhost:27017/database") cursor = connection.cursor() cursor.execute( 'SELECT name, email FROM users WHERE age > ? AND status = ?', [25, 'active'] ) ``` -------------------------------- ### SQL Operations to MongoDB Commands Source: https://github.com/passren/pymongosql/blob/main/README.md This table outlines the direct translation of common SQL operations into their equivalent MongoDB commands. ```json {find: col, projection: {...}} ``` ```json {find: col, filter: {...}} ``` ```json {find: ..., sort: {col: 1/-1}} ``` ```json {find: ..., limit: n} ``` ```json {find: ..., skip: n} ``` ```json collection.aggregate([{$group: {_id: null, ...}}, {$project: ...}]) ``` ```json collection.aggregate([{$group: {_id: null, ...}}, {$project: ...}]) ``` ```json collection.aggregate([{$group: {_id: null, ...}}, {$project: ...}]) ``` ```json collection.aggregate([{$group: {_id: null, ...}}, {$project: ...}]) ``` ```json collection.aggregate(pipeline) ``` ```json {insert: col, documents: [...]} ``` ```json {update: col, updates: [{q: filter, u: {$set: {...}}, multi: true}]} ``` ```json {delete: col, deletes: [{q: filter, limit: 0}]} ``` ```json {create: v, viewOn: col, pipeline: [...]} ``` ```json {drop: v} ``` ```json {explain: , verbosity: "queryPlanner"} ``` -------------------------------- ### PyMongoSQL DictCursor (Dictionary Results) Source: https://github.com/passren/pymongosql/blob/main/README.md Illustrates using DictCursor to fetch rows as dictionaries, enabling access to data by column name. This is often more readable than using indices. ```python from pymongosql.cursor import DictCursor cursor = connection.cursor(DictCursor) cursor.execute('SELECT name, email FROM users') row = cursor.fetchone() print(row['name']) # Access by column name ``` -------------------------------- ### PyMongoSQL Context Manager Support Source: https://github.com/passren/pymongosql/blob/main/README.md Utilize context managers for automatic connection and cursor management, ensuring resources are properly closed. This simplifies resource handling and prevents leaks. ```python from pymongosql import connect with connect(host="mongodb://localhost:27017/database") as conn: with conn.cursor() as cursor: cursor.execute('SELECT COUNT(*) as total FROM users') result = cursor.fetchone() print(f"Total users: {result[0]}") ``` -------------------------------- ### Parameterized DELETE Statements in SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Use positional parameters with '?' placeholders for safe and efficient deletion, preventing SQL injection. ```python # Positional parameters using ? placeholders cursor.execute( "DELETE FROM Music WHERE artist = ? AND year < ?", ["Charlie", 2021] ) ``` -------------------------------- ### Parameterized INSERT VALUES (Named) Source: https://github.com/passren/pymongosql/blob/main/README.md Perform parameterized inserts using standard SQL INSERT VALUES syntax with named (:name) placeholders. This offers clarity and flexibility when inserting data. ```python # Named parameters (:name) cursor.execute( "INSERT INTO Music (title, artist) VALUES (:title, :artist)", {"title": "Song I", "artist": "Iris"} ) ``` -------------------------------- ### SQL Clauses to MongoDB Query Components Source: https://github.com/passren/pymongosql/blob/main/README.md This table maps common SQL clauses to their MongoDB query equivalents, illustrating how to construct queries. ```json projection: {col1: 1, col2: 1} ``` ```json _(no projection)_ ``` ```json Column alias applied in result set ``` ```json find: "collection" ``` ```json sort: {col: 1} ``` ```json sort: {col: -1} ``` ```json limit: n ``` ```json skip: n ``` ```json {$group: {_id: null, count: {$sum: 1}}} ``` ```json {$group: {_id: null, sum: {$sum: "$field"}}} ``` ```json {$group: {_id: null, avg: {$avg: "$field"}}} ``` ```json {$group: {_id: null, min: {$min: "$field"}}} ``` ```json {$group: {_id: null, max: {$max: "$field"}}} ``` -------------------------------- ### Project Specific Fields from Aggregation Source: https://github.com/passren/pymongosql/blob/main/README.md Select specific fields from the results of a MongoDB aggregation pipeline using standard SQL SELECT syntax. This projection is applied after the aggregation. ```python # Select specific fields from aggregation results cursor.execute( "SELECT _id, total FROM users.aggregate('[{\"$\"$group\": {\"_id\": \"$city\", \"total\": {\"$sum\": 1}}}]', '{}')" ) ``` -------------------------------- ### Parameterized INSERT VALUES (Positional) Source: https://github.com/passren/pymongosql/blob/main/README.md Perform parameterized inserts using standard SQL INSERT VALUES syntax with positional (?) placeholders. This is a secure way to insert data with variable values. ```python # Positional parameters (?) cursor.execute( "INSERT INTO Music (title, artist, year) VALUES (?, ?, ?)", ["Song H", "Henry", 2025] ) ``` -------------------------------- ### Execute MongoDB Aggregate (Database-Level) Source: https://github.com/passren/pymongosql/blob/main/README.md Execute a native MongoDB aggregation pipeline at the database level using the unqualified aggregate() function. Options like allowDiskUse can be specified in the options JSON string. ```python cursor.execute( "SELECT * FROM aggregate('[{\"$\"$match\": {\"status\": \"active\"}}]', '{\"allowDiskUse\": true}')" ) results = cursor.fetchall() ``` -------------------------------- ### Check MongoDB Container Status Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Verify if the MongoDB test container is running. This command is useful for debugging. ```bash python mongo_test_helper.py status ``` -------------------------------- ### MongoDB Connection URI for Superset Source: https://github.com/passren/pymongosql/blob/main/README.md Use this connection URI format to connect to your MongoDB instance with superset mode enabled. For MongoDB Atlas, use the mongodb+srv:// format. ```text mongodb://username:password@host:port/database?mode=superset ``` ```text mongodb+srv://username:password@host/database?mode=superset ``` -------------------------------- ### Insert Multiple Documents (PartiQL-Style Bag Syntax) Source: https://github.com/passren/pymongosql/blob/main/README.md Insert multiple documents into a MongoDB collection using the PartiQL bag syntax for object literals. This allows for efficient insertion of several records in one statement. ```python cursor.execute( "INSERT INTO Music << {'title': 'Song B', 'artist': 'Bob'}, {'title': 'Song C', 'artist': 'Charlie'} >>" ) ``` -------------------------------- ### Delete Documents with Logical Operators in SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Combine multiple conditions in the WHERE clause using logical operators like AND and OR for precise deletion. ```python cursor.execute( "DELETE FROM Music WHERE year = 2019 AND available = false" ) ``` -------------------------------- ### Execute MongoDB Aggregate (Collection-Specific) Source: https://github.com/passren/pymongosql/blob/main/README.md Use the aggregate() function with a collection-specific path to execute a native MongoDB aggregation pipeline. The pipeline and options must be valid JSON strings. ```python cursor.execute( "SELECT * FROM users.aggregate('[{\"$\"$match\": {\"age\": {\"$gt\": 25}}}, {\"$\"$group\": {\"_id\": \"$city\", \"count\": {\"$sum\": 1}}}]', '{}')" ) results = cursor.fetchall() ``` -------------------------------- ### DML Mapping Details Source: https://github.com/passren/pymongosql/blob/main/README.md This section details the specifics of mapping SQL Data Manipulation Language (DML) statements to MongoDB behaviors. ```json Single document insert ``` ```json Multi-document insert ``` ```json Columns and values zipped into document ``` ```json {$set: {f1: v1}} with multi: true ``` ```json {q: {}, limit: 0} ``` ```json {q: filter, limit: 0} ``` -------------------------------- ### Delete Documents with WHERE Clause in SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Filter documents for deletion using a WHERE clause with standard SQL comparison operators. ```python cursor.execute("DELETE FROM Music WHERE year < 2020") ``` -------------------------------- ### Count Total Records with COUNT(*) Source: https://github.com/passren/pymongosql/blob/main/README.md Calculate the total number of records in a table using the COUNT(*) aggregate function. The result is aliased as 'total'. ```python cursor.execute("SELECT COUNT(*) AS total FROM users") row = cursor.fetchone() print(f"Total users: {row[0]}") ``` -------------------------------- ### Stop MongoDB Container Source: https://github.com/passren/pymongosql/blob/main/tests/README.md Use this command to gracefully stop the running MongoDB test container. This should be done after tests are completed. ```bash python mongo_test_helper.py stop ``` -------------------------------- ### Insert Single Document (PartiQL-Style) Source: https://github.com/passren/pymongosql/blob/main/README.md Insert a single document into a MongoDB collection using PartiQL-style object literals. This is a concise way to insert one record at a time. ```python cursor.execute( "INSERT INTO Music {'title': 'Song A', 'artist': 'Alice', 'year': 2021}" ) ``` -------------------------------- ### Stop Docker Compose for Tests Source: https://github.com/passren/pymongosql/blob/main/tests/README.md This command stops and removes the containers, networks, and volumes defined in docker-compose.test.yml. Ensure you are in the tests directory. ```bash docker-compose -f docker-compose.test.yml down ``` -------------------------------- ### Drop MongoDB View with SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Remove a MongoDB view using the SQL DROP VIEW syntax. ```python cursor.execute("DROP VIEW active_users") ``` -------------------------------- ### Manage ACID Transactions with PyMongoSQL Source: https://github.com/passren/pymongosql/blob/main/README.md Utilize DB API 2.0 transaction methods (begin, commit, rollback) for ACID-compliant operations. Requires a replica set or sharded cluster. ```python from pymongosql import connect connection = connect(host="mongodb://localhost:27017/database") try: connection.begin() # Start transaction cursor = connection.cursor() cursor.execute('UPDATE accounts SET balance = 100 WHERE id = ?', [1]) cursor.execute('UPDATE accounts SET balance = 200 WHERE id = ?', [2]) connection.commit() # Commit all changes print("Transaction committed successfully") except Exception as e: connection.rollback() # Rollback on error print(f"Transaction failed: {e}") finally: connection.close() ``` -------------------------------- ### Count Records with WHERE Clause Source: https://github.com/passren/pymongosql/blob/main/README.md Count records that meet specific criteria defined in a WHERE clause, combining boolean and comparison operators. ```python cursor.execute("SELECT COUNT(*) AS total FROM users WHERE active = true AND age > 30") ``` -------------------------------- ### Parameterized UPDATE Source: https://github.com/passren/pymongosql/blob/main/README.md Perform parameterized updates using positional (?) placeholders in the SQL UPDATE statement. This is a secure method for updating data with variable values. ```python # Positional parameters using ? placeholders cursor.execute( "UPDATE Music SET price = ?, stock = ? WHERE artist = ?", [24.99, 50, "Bob"] ) ``` -------------------------------- ### Convert String to Datetime with str_to_datetime Source: https://github.com/passren/pymongosql/blob/main/README.md Use str_to_datetime to convert ISO 8601 or custom formatted strings to datetime objects for filtering. Supports UTC timezone and standard comparison operators. ```python cursor.execute("SELECT * FROM events WHERE created_at >= str_to_datetime('2024-01-15T10:30:00Z')") ``` ```python cursor.execute("SELECT * FROM events WHERE created_at < str_to_datetime('03/15/2024', '%m/%d/%Y')") ``` -------------------------------- ### Multiple Aggregate Functions Source: https://github.com/passren/pymongosql/blob/main/README.md Compute multiple aggregate values (count, average, minimum, maximum) for a field in a single query. ```python cursor.execute("SELECT COUNT(*) AS cnt, AVG(price) AS avg_price, MIN(price) AS cheapest, MAX(price) AS priciest FROM products") ``` -------------------------------- ### Sort and Limit Aggregation Results Source: https://github.com/passren/pymongosql/blob/main/README.md Sort and limit the results of a MongoDB aggregation pipeline using ORDER BY and LIMIT clauses. These clauses are applied in Python after the aggregation completes. ```python # Sort and limit aggregation results cursor.execute( "SELECT * FROM products.aggregate('[{\"$\"$match\": {\"category\": \"Electronics\"}}]', '{}') ORDER BY price DESC LIMIT 10" ) ``` -------------------------------- ### Nested Field and Array Access Source: https://github.com/passren/pymongosql/blob/main/README.md This table demonstrates how to access nested fields and array elements in MongoDB using dot notation, mirroring SQL syntax. ```json profile.name ``` ```json account.profile.name ``` ```json items.0.name ``` -------------------------------- ### Delete All Documents in MongoDB with SQL Source: https://github.com/passren/pymongosql/blob/main/README.md Use a simple DELETE FROM collection statement to remove all documents. Ensure you have a cursor object available. ```python cursor.execute("DELETE FROM Music") ``` -------------------------------- ### Using DictCursor for Dictionary Results Source: https://github.com/passren/pymongosql/blob/main/README.md Employ DictCursor to retrieve query results as dictionaries, allowing access to columns by name instead of index. This enhances code readability and maintainability. ```python from pymongosql import connect from pymongosql.cursor import DictCursor with connect(host="mongodb://localhost:27017/database") as conn: with conn.cursor(DictCursor) as cursor: cursor.execute('SELECT COUNT(*) as total FROM users') result = cursor.fetchone() print(f"Total users: {result['total']}") ``` -------------------------------- ### Update with Logical Operators Source: https://github.com/passren/pymongosql/blob/main/README.md Update documents based on conditions involving logical operators (AND, OR) within the WHERE clause of a SQL UPDATE statement. This enables complex filtering for updates. ```python cursor.execute( "UPDATE Music SET price = 9.99 WHERE year = 2020 AND stock > 5" ) ``` -------------------------------- ### Count Records with OR Conditions Source: https://github.com/passren/pymongosql/blob/main/README.md Count records that satisfy at least one of the conditions specified using the OR logical operator in the WHERE clause. ```python cursor.execute("SELECT COUNT(*) AS cnt FROM users WHERE age < 26 OR age > 40") ``` -------------------------------- ### Insert Multiple Rows (Standard SQL VALUES) Source: https://github.com/passren/pymongosql/blob/main/README.md Insert multiple rows into a MongoDB collection using standard SQL INSERT VALUES syntax. This allows for inserting several records efficiently in one statement. ```python cursor.execute( "INSERT INTO Music (title, artist, year) VALUES ('Song F', 'Frank', 2023), ('Song G', 'Grace', 2024)" ) ``` -------------------------------- ### Convert String to Timestamp with str_to_timestamp Source: https://github.com/passren/pymongosql/blob/main/README.md Use str_to_timestamp to convert ISO 8601 or custom formatted strings to BSON Timestamp objects for filtering. Supports UTC timezone and standard comparison operators. ```python cursor.execute("SELECT * FROM logs WHERE timestamp > str_to_timestamp('2024-01-15T00:00:00Z')") ``` ```python cursor.execute("SELECT * FROM logs WHERE timestamp < str_to_timestamp('01/15/2024', '%m/%d/%Y')") ``` -------------------------------- ### Insert Single Row (Standard SQL VALUES) Source: https://github.com/passren/pymongosql/blob/main/README.md Insert a single row into a MongoDB collection using standard SQL INSERT VALUES syntax with a column list. This provides a familiar SQL way to insert data. ```python cursor.execute( "INSERT INTO Music (title, artist, year) VALUES ('Song E', 'Eve', 2022)" ) ``` -------------------------------- ### Check Deleted Row Count After SQL DELETE Source: https://github.com/passren/pymongosql/blob/main/README.md After executing a DELETE statement, the `cursor.rowcount` attribute provides the number of documents affected. ```python cursor.execute("DELETE FROM Music WHERE available = false") print(f"Deleted {cursor.rowcount} documents") ``` -------------------------------- ### Update All Documents Source: https://github.com/passren/pymongosql/blob/main/README.md Update all documents in a MongoDB collection using a standard SQL UPDATE statement without a WHERE clause. Use with caution as it affects all records. ```python cursor.execute("UPDATE Music SET available = false") ``` -------------------------------- ### SQL WHERE Operators to MongoDB Filter Operators Source: https://github.com/passren/pymongosql/blob/main/README.md This table shows how SQL WHERE clause operators are translated into MongoDB filter expressions. ```json {field: value} ``` ```json {field: {$ne: value}} ``` ```json {field: {$gt: value}} ``` ```json {field: {$gte: value}} ``` ```json {field: {$lt: value}} ``` ```json {field: {$lte: value}} ``` ```json {field: {$regex: "pat.*"}} ``` ```json {field: {$in: [a, b, c]}} ``` ```json {field: {$nin: [a, b]}} ``` ```json {$and: [{field: {$gte: a}}, {field: {$lte: b}}]} ``` ```json {field: {$eq: null}} ``` ```json {field: {$ne: null}} ``` ```json {$and: [filter1, filter2]} ``` ```json {$or: [filter1, filter2]} ``` ```json {$not: filter} ``` -------------------------------- ### Update Documents with WHERE Clause Source: https://github.com/passren/pymongosql/blob/main/README.md Update specific documents in a MongoDB collection by adding a WHERE clause to the SQL UPDATE statement. This allows for targeted modifications. ```python cursor.execute("UPDATE Music SET price = 14.99 WHERE year < 2020") ``` -------------------------------- ### Filter Aggregation Results Source: https://github.com/passren/pymongosql/blob/main/README.md Filter aggregation results using a WHERE clause after the aggregation has been executed. Note that this filtering happens in Python, not on MongoDB. ```python # Filter aggregation results cursor.execute( "SELECT * FROM users.aggregate('[{\"$\"$group\": {\"_id\": \"$city\", \"total\": {\"$sum\": 1}}}]', '{}') WHERE total > 100" ) ``` -------------------------------- ### Check Updated Row Count Source: https://github.com/passren/pymongosql/blob/main/README.md Check the number of documents affected by an UPDATE statement by accessing the cursor.rowcount attribute after execution. This confirms how many records were modified. ```python cursor.execute("UPDATE Music SET available = false WHERE year = 2020") print(f"Updated {cursor.rowcount} documents") ``` -------------------------------- ### Update Multiple Fields Source: https://github.com/passren/pymongosql/blob/main/README.md Update multiple fields within documents in a MongoDB collection using a single SQL UPDATE statement. This is efficient for modifying several attributes at once. ```python cursor.execute( "UPDATE Music SET price = 19.99, available = true WHERE artist = 'Alice'" ) ``` -------------------------------- ### Update Nested Fields Source: https://github.com/passren/pymongosql/blob/main/README.md Update fields within nested documents in MongoDB using dot notation in the SQL UPDATE statement. This allows for precise modification of deeply structured data. ```python cursor.execute( "UPDATE Music SET details.publisher = 'XYZ Records' WHERE title = 'Song A'" ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.