Skip to content

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

  • Fixes FindQuery.count() not forwarding pymongo_kwargs to the count_documents() call
  • Resolves issue where hints and other pymongo parameters were being ignored during count operations

Changes

  • Updated FindQuery.count() to merge self.pymongo_kwargs into the kwargs dict before passing to count_documents()
  • This ensures all pymongo parameters (like hint for index optimization) are properly forwarded

Test plan

  • Verified existing count tests still pass with the change
  • Confirmed pymongo_kwargs are now included in the count_documents call
  • Maintainers can verify with MyCollection.find({...}, hint="my_index").count() now correctly uses the index

Fixes #1258

veeceey and others added 3 commits February 7, 2026 23:07
FindQuery.count() was not forwarding pymongo_kwargs (like hint)
to the count_documents call. This caused performance issues when
users tried to use hints for indexed queries.

Updated FindQuery.count() to merge pymongo_kwargs into the kwargs
dict before passing to count_documents, ensuring all pymongo
parameters are properly forwarded.

Fixes BeanieODM#1258
…tor imports conditional

ConfigDict only exists in pydantic v2, and root_validator is only in pydantic v1.
Move these imports to conditional blocks based on IS_PYDANTIC_V2 to fix import errors
when running tests with pydantic 1.10.18.
@CAPITAINMARVEL
Copy link
Contributor

Summary

  • Fixes FindQuery.count() not forwarding pymongo_kwargs to the count_documents() call
  • Resolves issue where hints and other pymongo parameters were being ignored during count operations

Changes

  • Updated FindQuery.count() to merge self.pymongo_kwargs into the kwargs dict before passing to count_documents()
  • This ensures all pymongo parameters (like hint for index optimization) are properly forwarded

Test plan

  • Verified existing count tests still pass with the change
  • Confirmed pymongo_kwargs are now included in the count_documents call
  • Maintainers can verify with MyCollection.find({...}, hint="my_index").count() now correctly uses the index

Fixes #1258

can you sync fork with the main (beanie) so that test can be working

@CAPITAINMARVEL
Copy link
Contributor

Summary

  • Fixes FindQuery.count() not forwarding pymongo_kwargs to the count_documents() call
  • Resolves issue where hints and other pymongo parameters were being ignored during count operations

Changes

  • Updated FindQuery.count() to merge self.pymongo_kwargs into the kwargs dict before passing to count_documents()
  • This ensures all pymongo parameters (like hint for index optimization) are properly forwarded

Test plan

  • Verified existing count tests still pass with the change
  • Confirmed pymongo_kwargs are now included in the count_documents call
  • Maintainers can verify with MyCollection.find({...}, hint="my_index").count() now correctly uses the index

Fixes #1258

can you sync fork with the main (beanie) so that test can be working

git remote add upstream https://github.com/BeanieODM/beanie.git
git fetch upstream
git merge upstream/main

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.

[BUG] FindQuery.count() ignores pymongo_kwargs

2 participants