Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,56 @@ Results are returned in Extended JSON (Relaxed) format:
| BinData() | `BinData(subtype, base64)` | |
| RegExp() | `RegExp("pattern", "flags")`, `/pattern/flags` | |

### Milestone 2: Write Operations (Planned)
### Milestone 2: Write Operations (Current)

#### Insert Commands

| Command | Syntax | Status |
|---------|--------|--------|
| db.collection.insertOne() | `insertOne(document, options)` | Supported |
| db.collection.insertMany() | `insertMany(documents, options)` | Supported |

#### Update Commands

| Command | Syntax | Status |
|---------|--------|--------|
| db.collection.updateOne() | `updateOne(filter, update, options)` | Supported |
| db.collection.updateMany() | `updateMany(filter, update, options)` | Supported |
| db.collection.replaceOne() | `replaceOne(filter, replacement, options)` | Supported |

#### Delete Commands

| Command | Syntax | Status |
|---------|--------|--------|
| db.collection.deleteOne() | `deleteOne(filter, options)` | Supported |
| db.collection.deleteMany() | `deleteMany(filter, options)` | Supported |

#### Atomic Find-and-Modify Commands

| Command | Syntax | Status |
|---------|--------|--------|
| db.collection.insertOne() | `insertOne(document)` | Not yet supported |
| db.collection.insertMany() | `insertMany(documents)` | Not yet supported |
| db.collection.updateOne() | `updateOne(filter, update)` | Not yet supported |
| db.collection.updateMany() | `updateMany(filter, update)` | Not yet supported |
| db.collection.deleteOne() | `deleteOne(filter)` | Not yet supported |
| db.collection.deleteMany() | `deleteMany(filter)` | Not yet supported |
| db.collection.replaceOne() | `replaceOne(filter, replacement)` | Not yet supported |
| db.collection.findOneAndUpdate() | `findOneAndUpdate(filter, update)` | Not yet supported |
| db.collection.findOneAndReplace() | `findOneAndReplace(filter, replacement)` | Not yet supported |
| db.collection.findOneAndDelete() | `findOneAndDelete(filter)` | Not yet supported |
| db.collection.findOneAndUpdate() | `findOneAndUpdate(filter, update, options)` | Supported |
| db.collection.findOneAndReplace() | `findOneAndReplace(filter, replacement, options)` | Supported |
| db.collection.findOneAndDelete() | `findOneAndDelete(filter, options)` | Supported |

#### Write Operation Options

| Option | Applies To | Description |
|--------|-----------|-------------|
| `writeConcern` | All write ops | Write concern settings (`w`, `j`, `wtimeout`*) |
| `bypassDocumentValidation` | Insert, Update, Replace, FindOneAndUpdate/Replace | Skip schema validation |
| `comment` | All write ops | Comment for server logs |
| `ordered` | insertMany | Execute inserts sequentially (default: true) |
| `upsert` | Update, Replace, FindOneAndUpdate/Replace | Insert if no match found |
| `hint` | Update, Replace, Delete, FindOneAnd* | Force index usage |
| `collation` | Update, Replace, Delete, FindOneAnd* | String comparison rules |
| `arrayFilters` | updateOne, updateMany, findOneAndUpdate | Array element filtering |
| `let` | Update, Replace, Delete, FindOneAnd* | Variables for expressions |
| `sort` | updateOne, replaceOne, FindOneAnd* | Document selection order |
| `projection` | FindOneAnd* | Fields to return |
| `returnDocument` | FindOneAndUpdate/Replace | Return "before" or "after" |

*Note: `wtimeout` is parsed but ignored as it's not supported in MongoDB Go driver v2.

### Milestone 3: Administrative Operations (Planned)

Expand Down
11 changes: 6 additions & 5 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func TestPlannedOperation(t *testing.T) {
gc := gomongo.NewClient(client)
ctx := context.Background()

// insertOne is a planned M2 operation - should return PlannedOperationError
_, err := gc.Execute(ctx, dbName, "db.users.insertOne({ name: 'test' })")
// createIndex is a planned M3 operation - should return PlannedOperationError
_, err := gc.Execute(ctx, dbName, "db.users.createIndex({ name: 1 })")
require.Error(t, err)

var plannedErr *gomongo.PlannedOperationError
require.ErrorAs(t, err, &plannedErr)
require.Equal(t, "insertOne()", plannedErr.Operation)
require.Equal(t, "createIndex()", plannedErr.Operation)
}

func TestUnsupportedOperation(t *testing.T) {
Expand Down Expand Up @@ -78,8 +78,9 @@ func TestUnsupportedOptionError(t *testing.T) {
func TestMethodRegistryStats(t *testing.T) {
total := gomongo.MethodRegistryStats()

// Registry should contain M2 (10) + M3 (22) = 32 planned methods
require.Equal(t, 32, total, "expected 32 planned methods in registry (M2: 10, M3: 22)")
// Registry should contain M3 (22) planned methods
// M2 write operations have been implemented and removed from the registry
require.Equal(t, 22, total, "expected 22 planned methods in registry (M3: 22)")

// Log stats for visibility
t.Logf("Method Registry Stats: total=%d planned methods", total)
Expand Down
20 changes: 20 additions & 0 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ func Execute(ctx context.Context, client *mongo.Client, database string, op *tra
return executeEstimatedDocumentCount(ctx, client, database, op)
case translator.OpDistinct:
return executeDistinct(ctx, client, database, op)
case translator.OpInsertOne:
return executeInsertOne(ctx, client, database, op)
case translator.OpInsertMany:
return executeInsertMany(ctx, client, database, op)
case translator.OpUpdateOne:
return executeUpdateOne(ctx, client, database, op)
case translator.OpUpdateMany:
return executeUpdateMany(ctx, client, database, op)
case translator.OpReplaceOne:
return executeReplaceOne(ctx, client, database, op)
case translator.OpDeleteOne:
return executeDeleteOne(ctx, client, database, op)
case translator.OpDeleteMany:
return executeDeleteMany(ctx, client, database, op)
case translator.OpFindOneAndUpdate:
return executeFindOneAndUpdate(ctx, client, database, op)
case translator.OpFindOneAndReplace:
return executeFindOneAndReplace(ctx, client, database, op)
case translator.OpFindOneAndDelete:
return executeFindOneAndDelete(ctx, client, database, op)
default:
return nil, fmt.Errorf("unsupported operation: %s", statement)
}
Expand Down
Loading
Loading