feat: implement milestone 2 write operations#16
Conversation
Add support for 10 MongoDB write operations: Insert: - insertOne(document, options) - insertMany(documents, options) Update: - updateOne(filter, update, options) - updateMany(filter, update, options) - replaceOne(filter, replacement, options) Delete: - deleteOne(filter, options) - deleteMany(filter, options) Atomic find-and-modify: - findOneAndUpdate(filter, update, options) - findOneAndReplace(filter, replacement, options) - findOneAndDelete(filter, options) Supported options include: - writeConcern (w, j; wtimeout parsed but ignored in driver v2) - upsert, hint, collation, arrayFilters, let - bypassDocumentValidation, comment, ordered - sort, projection, returnDocument Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Implements Milestone 2 MongoDB write operations by adding parsing + execution support for 10 write methods, along with integration tests and updated documentation.
Changes:
- Add translator support for insert/update/replace/delete/findOneAnd* write operations and their supported options.
- Add executor implementations for all 10 write operations using the MongoDB Go driver v2.
- Add integration tests for write operations and update docs/registry to reflect M2 is now supported.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| write_test.go | Adds integration tests covering the 10 new write operations. |
| internal/translator/visitor.go | Routes parsed method calls to new write-operation extractors and op types. |
| internal/translator/types.go | Introduces new OpTypes and Operation fields for write operations/options. |
| internal/translator/method_registry.go | Removes M2 write methods from “planned” registry now that they’re implemented. |
| internal/translator/collection.go | Implements argument/option extraction for all Milestone 2 write methods. |
| internal/executor/write.go | Implements execution logic for the 10 write operations and response formatting. |
| internal/executor/executor.go | Wires new write operation types into the executor dispatch. |
| error_test.go | Updates planned-operation test expectations now that insertOne is implemented. |
| README.md | Updates Milestone 2 documentation from “planned” to “supported” and lists options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case "returnDocument": | ||
| if val, ok := opt.Value.(string); ok { | ||
| if val != "before" && val != "after" { | ||
| v.err = fmt.Errorf("%s() returnDocument must be 'before' or 'after'", methodName) | ||
| return |
There was a problem hiding this comment.
returnDocument is accepted for all findOneAnd* methods here, but it is documented as only applying to findOneAndUpdate/Replace (and the executor ignores op.ReturnDocument for findOneAndDelete). This results in silently ignoring a user-supplied option for findOneAndDelete. Consider rejecting returnDocument (UnsupportedOptionError) when methodName == "findOneAndDelete" to match the documented API surface and avoid surprising behavior.
Summary
Implement all 10 MongoDB write operations for Milestone 2:
Insert:
insertOne(document, options)insertMany(documents, options)Update:
updateOne(filter, update, options)updateMany(filter, update, options)replaceOne(filter, replacement, options)Delete:
deleteOne(filter, options)deleteMany(filter, options)Atomic find-and-modify:
findOneAndUpdate(filter, update, options)findOneAndReplace(filter, replacement, options)findOneAndDelete(filter, options)Supported options:
writeConcernbypassDocumentValidationcommentorderedupserthintcollationarrayFiltersletsortprojectionreturnDocumentTest plan
write_test.go🤖 Generated with Claude Code