Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning on newer pymongo #1202

Closed
nicolaiarocci opened this Issue Oct 11, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@nicolaiarocci
Copy link
Member

nicolaiarocci commented Oct 11, 2018

DeprecationWarning: count is deprecated. Use Collection.count_documents instead. is returned by pymongo 3.7.2. Consider updating the code to silence the warning, and of course pin to pymongo 3.7+

@nicolaiarocci nicolaiarocci added this to the 0.8.2 milestone Oct 11, 2018

einarhuseby added a commit to einarhuseby/eve that referenced this issue Jan 27, 2019

@einarhuseby

This comment has been minimized.

Copy link
Contributor

einarhuseby commented Jan 27, 2019

@nicolaiarocci - I was looking into this and soon found that

cursor = app.data.find(resource, req, lookup)
count = cursor.count()

needs to be replaced like

count = collection.count_documents({"foo": "bar"})

For Eve I think either a new count method for the datalayer count = app.data.count(resource, req, lookup) or handle it in find and change the return signature from cursor to count, cursor.

Both will break the current base datalayer. Personally I favor the latter. What are your thoughts on this?

Also pymongo 3.7 added estimated_document_count. See also this SO answer

This could possible be of use; OPTIMIZE_PAGINATION_FOR_SPEED could be replaced with something like PAGINATION_STRATEGY and a corresponding resource override pagination_strategy with options full count, estimated count and no count.

I could provide a PR to see how it pans out.

@nicolaiarocci

This comment has been minimized.

Copy link
Member Author

nicolaiarocci commented Jan 28, 2019

I could provide a PR to see how it pans out.

Please do.

einarhuseby added a commit to einarhuseby/eve that referenced this issue Jan 30, 2019

Merge pull request #10 from einarhuseby/deprecation_warning_newer_pym…
…ongo_#1202

Deprecation warning newer pymongo pyeve#1202

nicolaiarocci added a commit that referenced this issue Mar 26, 2019

Bump PyMongo to 3.7+ and fix DeprecationWarnings
Adds a last_document_count property to the mongo data layer. This
approach does not break the base DataLayer contract.

In determining the number of documents we do our best to use the new
count_documents() method introduced with PyMongo 3.7. However,
count_documents() does not support the $where operator. It must be
replaced with $expr, which in turn is not supported by older Mongos
(3.4-). Since we do not want to impose a limit on the supported DB
version, for the time being we will fallback to the deprecated
cursor.count() if needed.

See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.count

Closes #1202.

nicolaiarocci added a commit that referenced this issue Mar 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.