Skip to content

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Jan 22, 2026

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:

Option Applies To
writeConcern All write ops
bypassDocumentValidation Insert, Update, Replace, FindOneAndUpdate/Replace
comment All write ops
ordered insertMany
upsert Update, Replace, FindOneAndUpdate/Replace
hint Update, Replace, Delete, FindOneAnd*
collation Update, Replace, Delete, FindOneAnd*
arrayFilters updateOne, updateMany, findOneAndUpdate
let Update, Replace, Delete, FindOneAnd*
sort updateOne, replaceOne, FindOneAnd*
projection FindOneAnd*
returnDocument FindOneAndUpdate/Replace

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

Test plan

  • All existing tests pass
  • Added integration tests for all 10 write operations in write_test.go
  • Tests cover basic operations, upsert, returnDocument, sort options
  • Lint passes with 0 issues

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings January 22, 2026 09:53
@d-bytebase d-bytebase merged commit 88ce61b into main Jan 22, 2026
6 checks passed
@d-bytebase d-bytebase deleted the vk/6330-gomongo-mileston branch January 22, 2026 09:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1740 to +1744
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
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants