Skip to content

collection-level count methods now accept filters#79

Open
dill0wn wants to merge 1 commit into
masterfrom
dw/add-filter-to-count
Open

collection-level count methods now accept filters#79
dill0wn wants to merge 1 commit into
masterfrom
dw/add-filter-to-count

Conversation

@dill0wn

@dill0wn dill0wn commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Rather than rely on a cursor for filtered counts, let the collection's count method use pymongo.collection.count_documents(filter, ...) under the hood so it's possible to get a count with Collection.m.count({'some': 'filter'})

I have only updated ming.Session.count which is accessible from Document.m.count(...). There are a few other def count wrappers/implementations that might also be helpful to use this.

Additionally, pymongo itself has deprecated db.collection.find().count() and prefer count_documents(). See https://pymongo.readthedocs.io/en/4.14.1/common-issues.html#deprecationwarning-count-is-deprecated

With that in mind, maybe a more thorough audit is in order.

Rather than rely on a cursor for filtered counts, let the collection's
count method use `pymongo.collection.count_documents(filter, ...)`
under the hood so it's possible to get a count with
`Collection.m.count({'some': 'filter'})`
@brondsem

Copy link
Copy Markdown
Collaborator

I am not sure if we need Document.m.count(...) since we already have Document.m.find(..).count()

Regarding count_documents, Ming's count() method is using that. I don't think we're calling the pymongo deprecated count() anywhere (although I could be wrong)

@dill0wn

dill0wn commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

That's fair. Ming is an abstraction after all. And the two are functionally (and performantly) roughly equivalent AFAICT. Maybe not needed?

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.

2 participants