Skip to content

feat: add findOne() operation support - #5

Merged
h3n4l merged 1 commit into
mainfrom
vk/93f4-mvp-of-gomongo-s
Jan 15, 2026
Merged

feat: add findOne() operation support#5
h3n4l merged 1 commit into
mainfrom
vk/93f4-mvp-of-gomongo-s

Conversation

@h3n4l

@h3n4l h3n4l commented Jan 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Add findOne() operation support to complete the MVP read operations
  • Supports filters, sort, skip, and projection options
  • Returns empty result (0 rows) when no document matches, consistent with MongoDB behavior

Changes

  • translator.go: Add opFindOne type and extractFindOneFilter() method
  • executor.go: Add executeFindOne() using Go driver's FindOne method
  • executor_test.go: Add 4 comprehensive test functions for findOne

Test plan

  • TestFindOneEmptyCollection - empty result on empty collection
  • TestFindOneWithDocuments - basic findOne returns 1 document
  • TestFindOneWithFilter - various filters (string, number, $gt, no match)
  • TestFindOneWithOptions - sort, skip, and projection options
  • All 16 tests pass

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings January 15, 2026 03:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 opFindOne operation type and extractFindOneFilter() method in translator
  • Added executeFindOne() function in executor that uses MongoDB Go driver's FindOne method
  • 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 thread translator.go
Comment thread executor_test.go
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)
}

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@h3n4l
h3n4l merged commit 4299ca8 into main Jan 15, 2026
8 checks passed
@h3n4l
h3n4l deleted the vk/93f4-mvp-of-gomongo-s branch January 15, 2026 03:51
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