feat: add findOne() operation support - #5
Merged
Merged
Conversation
- Add opFindOne operation type in translator - Implement extractFindOneFilter() to parse filter documents - Add executeFindOne() using Go driver's FindOne method - Support sort, skip, and projection options for findOne - Return empty result (not error) when no document matches - Update TestUnsupportedOperation to use insertOne instead - Add comprehensive tests for findOne with filters and options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for the findOne() operation to complete the MVP read operations. The implementation closely mirrors the existing find() operation but returns at most one document.
Changes:
- Added
opFindOneoperation type andextractFindOneFilter()method in translator - Added
executeFindOne()function in executor that uses MongoDB Go driver'sFindOnemethod - Added 4 comprehensive test functions covering empty collections, basic usage, filters, and options (sort, skip, projection)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| translator.go | Adds opFindOne constant and extractFindOneFilter() method for parsing findOne operations |
| executor.go | Implements executeFindOne() with support for filters and query options |
| executor_test.go | Adds comprehensive tests for findOne operations and updates unsupported operation test |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+98
to
+110
| func TestFindOneEmptyCollection(t *testing.T) { | ||
| client, cleanup := setupTestContainer(t) | ||
| defer cleanup() | ||
|
|
||
| gc := gomongo.NewClient(client) | ||
| ctx := context.Background() | ||
|
|
||
| result, err := gc.Execute(ctx, "testdb", "db.users.findOne()") | ||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| require.Equal(t, 0, result.RowCount) | ||
| require.Empty(t, result.Rows) | ||
| } |
There was a problem hiding this comment.
Consider adding a test case for findOne with an explicit empty filter document, similar to TestFindWithEmptyFilter. This would ensure that both findOne() and findOne({}) behave identically and handle the empty filter case correctly.
d-bytebase
approved these changes
Jan 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
findOne()operation support to complete the MVP read operationsChanges
opFindOnetype andextractFindOneFilter()methodexecuteFindOne()using Go driver'sFindOnemethodTest plan
TestFindOneEmptyCollection- empty result on empty collectionTestFindOneWithDocuments- basic findOne returns 1 documentTestFindOneWithFilter- various filters (string, number, $gt, no match)TestFindOneWithOptions- sort, skip, and projection options🤖 Generated with Claude Code