The UPDATE DOCUMENTS statement modifies one or more fields in existing documents within a bundle. Updates are applied to all documents matching the WHERE clause criteria.
⚠️ WARNING: Updates are permanent and cannot be undone. Always verify your WHERE clause before executing updates.
UPDATE DOCUMENTS IN BUNDLE "<BUNDLE_NAME>"
(<FIELD> = <VALUE>)
WHERE <CONDITION>;
Alternative (singular form):
UPDATE DOCUMENT IN BUNDLE "<BUNDLE_NAME>"
(<FIELD> = <VALUE>)
WHERE <CONDITION>;
Components:
UPDATE DOCUMENTS - Specifies update operation (DOCUMENT or DOCUMENTS)IN BUNDLE "<BUNDLE_NAME>" - Target bundle name (quoted)(<FIELD> = <VALUE>) - Field assignments in parenthesesWHERE <CONDITION> - Filter criteria (required)The UPDATE keyword indicates a document modification operation.
Characteristics:
The DOCUMENTS keyword (or singular DOCUMENT) specifies that you are updating documents.
Characteristics:
DOCUMENT and DOCUMENTS are validIN BUNDLEValid Forms:
UPDATE DOCUMENTS IN BUNDLE ...
UPDATE DOCUMENT IN BUNDLE ...
The IN BUNDLE keywords specify the source bundle containing documents to update.
Syntax:
IN BUNDLE "<BUNDLE_NAME>"
Characteristics:
Valid Examples:
UPDATE DOCUMENTS IN BUNDLE "users" ...
UPDATE DOCUMENTS IN BUNDLE "order_items" ...
UPDATE DOCUMENTS IN BUNDLE "UserProfiles" ...
Field updates are specified in parentheses with assignment syntax: field = value
Syntax:
(<FIELD1> = <VALUE1>, <FIELD2> = <VALUE2>, ...)
Characteristics:
( ),= for assignment (not ==)The WHERE clause is required and defines which documents to update based on filtering conditions.
Syntax:
WHERE <field> <operator> <value>
Characteristics:
==, !=, <, >, <=, >=AND, ORUpdate one field at a time:
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "John Doe")
WHERE id = 1;
Notes:
name (can be quoted: "name")= (single equals)"John Doe" (string in quotes)Update multiple fields in one statement:
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "Jane", age = 30, active = true)
WHERE id = 2;
Notes:
SyndrDB supports the following value types in UPDATE statements:
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "Alice", email = "alice@example.com")
WHERE id = 1;
name = ""Integers:
UPDATE DOCUMENTS IN BUNDLE "products"
(quantity = 100, stock = 50)
WHERE sku = "ABC123";
Floats:
UPDATE DOCUMENTS IN BUNDLE "products"
(price = 99.99, discount = 0.15)
WHERE sku = "ABC123";
UPDATE DOCUMENTS IN BUNDLE "settings"
(enabled = true, verified = false)
WHERE name = "feature_x";
true or falseUPDATE DOCUMENTS IN BUNDLE "users"
(middle_name = NULL, suffix = NULL)
WHERE id = 3;
NULLSyndrDB supports the following comparison operators in WHERE clauses:
| Operator | Description | Example |
|---|---|---|
== |
Equal to | WHERE id == 1 |
!= |
Not equal to | WHERE status != "active" |
< |
Less than | WHERE age < 18 |
> |
Greater than | WHERE price > 100 |
<= |
Less than or equal | WHERE quantity <= 5 |
>= |
Greater than or equal | WHERE score >= 90 |
Note: WHERE clause uses == for comparison, while field updates use = for assignment.
Combine multiple conditions using logical operators:
| Operator | Description | Example |
|---|---|---|
AND |
Both conditions must be true | WHERE age > 18 AND status == "active" |
OR |
At least one condition must be true | WHERE role == "admin" OR role == "moderator" |
Precedence:
AND has higher precedence than ORUse parentheses () to group conditions and control evaluation order:
-- Update users who are either minors OR seniors, but only if inactive
UPDATE DOCUMENTS IN BUNDLE "users"
(status = "review")
WHERE (age < 18 OR age > 65) AND status == "inactive";
-- Update orders that are pending AND either high priority OR high value
UPDATE DOCUMENTS IN BUNDLE "orders"
(review_flag = true)
WHERE status == "pending" AND (priority == "high" OR amount > 1000);
Update string field:
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "John Doe")
WHERE id = 1;
Update numeric field:
UPDATE DOCUMENTS IN BUNDLE "products"
(price = 99)
WHERE sku = "ABC123";
Update boolean field:
UPDATE DOCUMENTS IN BUNDLE "settings"
(enabled = true)
WHERE name = "feature_x";
Set field to NULL:
UPDATE DOCUMENTS IN BUNDLE "users"
(middle_name = NULL)
WHERE id = 3;
Without semicolon (optional):
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "Bob")
WHERE id = 4
Update multiple fields with different types:
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "Jane", age = 30, active = true)
WHERE id = 2;
Update product details:
UPDATE DOCUMENTS IN BUNDLE "products"
(price = 99.99, stock = 150, available = true, last_updated = "2024-11-20")
WHERE category = "electronics";
Clear optional fields:
UPDATE DOCUMENTS IN BUNDLE "users"
(middle_name = NULL, suffix = NULL, nickname = NULL)
WHERE id = 5;
Integer value:
UPDATE DOCUMENTS IN BUNDLE "products"
(quantity = 100)
WHERE sku = "XYZ789";
Float value:
UPDATE DOCUMENTS IN BUNDLE "products"
(price = 99.99)
WHERE sku = "ABC123";
Boolean true:
UPDATE DOCUMENTS IN BUNDLE "settings"
(enabled = true)
WHERE name = "feature_x";
Boolean false:
UPDATE DOCUMENTS IN BUNDLE "settings"
(enabled = false)
WHERE name = "feature_y";
NULL value:
UPDATE DOCUMENTS IN BUNDLE "users"
(middle_name = NULL)
WHERE id = 3;
String with special characters:
UPDATE DOCUMENTS IN BUNDLE "users"
(email = "user@example.com", bio = "Software Engineer @ Tech Corp")
WHERE id = 10;
Simple equality:
UPDATE DOCUMENTS IN BUNDLE "users"
(last_login = "2024-11-20")
WHERE id = 1;
Comparison operators:
-- Greater than
UPDATE DOCUMENTS IN BUNDLE "products"
(clearance = true)
WHERE price > 1000;
-- Less than
UPDATE DOCUMENTS IN BUNDLE "inventory"
(reorder_flag = true)
WHERE stock < 10;
-- Not equal
UPDATE DOCUMENTS IN BUNDLE "users"
(status = "review")
WHERE role != "admin";
AND conditions:
UPDATE DOCUMENTS IN BUNDLE "orders"
(status = "processing")
WHERE payment_status == "paid" AND inventory_status == "available";
OR conditions:
UPDATE DOCUMENTS IN BUNDLE "users"
(tier = "premium")
WHERE total_purchases > 1000 OR subscription == "gold";
Complex grouped conditions:
UPDATE DOCUMENTS IN BUNDLE "products"
(featured = true)
WHERE (category == "electronics" OR category == "computers")
AND price < 500
AND stock > 10;
Age-based status update:
UPDATE DOCUMENTS IN BUNDLE "users"
(age_group = "senior")
WHERE age >= 65 AND status == "active";
Field names can be quoted if they contain special characters or match keywords:
Update using quoted field names:
UPDATE DOCUMENTS IN BUNDLE "users"
("FirstName" = "John", "LastName" = "Doe")
WHERE "UserID" = 123;
Mixed quoted and unquoted fields:
UPDATE DOCUMENTS IN BUNDLE "products"
("ProductID" = "NEW-123", name = "Updated Product")
WHERE id = 456;
Fields with special characters:
UPDATE DOCUMENTS IN BUNDLE "data"
("field-with-dashes" = "new-value", "field_with_underscores" = 42)
WHERE "record-id" == "abc-123";
Test WHERE clause with SELECT first:
-- 1. Preview what will be updated
SELECT * FROM "users" WHERE status == "pending";
-- 2. Then update if correct
UPDATE DOCUMENTS IN BUNDLE "users"
(status = "active")
WHERE status == "pending";
Use specific WHERE conditions:
-- ✅ Specific update
UPDATE DOCUMENTS IN BUNDLE "users"
(verified = true)
WHERE email == "user@example.com" AND verification_code == "ABC123";
Update multiple related fields together:
-- ✅ Atomic multi-field update
UPDATE DOCUMENTS IN BUNDLE "orders"
(status = "shipped", shipped_date = "2024-11-20", tracking = "TRK123")
WHERE id = 1001;
Use appropriate data types:
-- ✅ Correct types
UPDATE DOCUMENTS IN BUNDLE "products"
(price = 99.99, stock = 100, available = true)
WHERE sku = "ABC";
Update by unique identifiers when possible:
-- ✅ Update specific document
UPDATE DOCUMENTS IN BUNDLE "users"
(last_login = "2024-11-20")
WHERE DocumentID == "abc-123";
Use NULL to clear optional fields:
-- ✅ Clear optional data
UPDATE DOCUMENTS IN BUNDLE "users"
(temp_token = NULL, temp_token_expires = NULL)
WHERE id = 5;
Don't update without testing WHERE clause:
-- ❌ Test first!
UPDATE DOCUMENTS IN BUNDLE "users" (status = "deleted") WHERE active = false;
Don't use broad WHERE conditions on critical data:
-- ❌ Too broad!
UPDATE DOCUMENTS IN BUNDLE "accounts" (balance = 0) WHERE true == true;
Don't forget field type compatibility:
-- ❌ Wrong - age should be numeric
UPDATE DOCUMENTS IN BUNDLE "users" (age = "25") WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (age = 25) WHERE id = 1;
Don't use == in field assignments:
-- ❌ Wrong operator
UPDATE DOCUMENTS IN BUNDLE "users" (name == "John") WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (name = "John") WHERE id = 1;
Don't update without considering related data:
-- ❌ May break referential integrity
UPDATE DOCUMENTS IN BUNDLE "users" (id = 999) WHERE id = 1;
Error: expected keyword 'WHERE', got <token>
Solution: Always include WHERE clause.
UPDATE DOCUMENTS IN BUNDLE "users"
(name = "Bob")
WHERE id = 1; -- ✅ Correct
Error: bundle 'xyz' not found
Solution: Verify bundle name (case-sensitive) exists in database.
Error: UPDATE statement must specify at least one field to update
Solution: Provide at least one field assignment.
-- ❌ Wrong
UPDATE DOCUMENTS IN BUNDLE "users" () WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (name = "John") WHERE id = 1;
Error: expected '(' after bundle name
Solution: Enclose field assignments in parentheses.
-- ❌ Wrong
UPDATE DOCUMENTS IN BUNDLE "users" name = "Bob" WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (name = "Bob") WHERE id = 1;
Error: expected '=' after field name
Solution: Use single equals = for assignment (not ==).
-- ❌ Wrong
UPDATE DOCUMENTS IN BUNDLE "users" (name == "Bob") WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (name = "Bob") WHERE id = 1;
Error: failed to parse WHERE expression
Solution: Check WHERE clause uses == for comparison.
-- ❌ Wrong
UPDATE DOCUMENTS IN BUNDLE "users" (name = "Bob") WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "users" (name = "Bob") WHERE id == 1;
Error: type mismatch in field assignment
Solution: Ensure value types match field definitions.
-- ❌ Wrong - price should be numeric
UPDATE DOCUMENTS IN BUNDLE "products" (price = "99.99") WHERE id = 1;
-- ✅ Correct
UPDATE DOCUMENTS IN BUNDLE "products" (price = 99.99) WHERE id = 1;
Info: 0 documents updated
Explanation: No documents matched the WHERE clause criteria. This is not an error, but verify your WHERE clause is correct.
-- Single field update
UPDATE DOCUMENTS IN BUNDLE "bundle" (field = value) WHERE condition;
-- Multiple fields update
UPDATE DOCUMENTS IN BUNDLE "bundle"
(field1 = value1, field2 = value2)
WHERE condition;
-- Different value types
UPDATE DOCUMENTS IN BUNDLE "bundle"
(str_field = "text", num_field = 42, bool_field = true, null_field = NULL)
WHERE condition;
-- Complex WHERE
UPDATE DOCUMENTS IN BUNDLE "bundle"
(field = value)
WHERE (cond1 OR cond2) AND cond3;
| Context | Operator | Example |
|---|---|---|
| Field Assignment | = |
(name = "John") |
| WHERE Comparison | == |
WHERE id == 1 |
| Operator | Usage | Example |
|---|---|---|
== |
Equality | WHERE id == 1 |
!= |
Inequality | WHERE status != "active" |
< |
Less than | WHERE age < 18 |
> |
Greater than | WHERE price > 100 |
<= |
Less/equal | WHERE quantity <= 5 |
>= |
Greater/equal | WHERE score >= 90 |
| Operator | Usage | Example |
|---|---|---|
AND |
Both true | WHERE age > 18 AND verified == true |
OR |
Either true | WHERE role == "admin" OR role == "mod" |
| Type | Example | Notes |
|---|---|---|
| String | "John" |
Double quotes |
| Integer | 25 |
No quotes |
| Float | 99.99 |
Decimal point |
| Boolean | true, false |
Lowercase, no quotes |
| NULL | NULL |
Uppercase, clears field |
| Type | Example | When to Use |
|---|---|---|
| Unquoted | name |
Standard field names |
| Quoted | "FirstName" |
Special characters, case-sensitive |
Version: SyndrDB 1.0
Last Updated: November 2024
Status: ✅ Implemented and tested