Skip to content

Commit

Permalink
PYTHON-1642 - Replace count() with count_documents({}) in docs (#376)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7f1939e)
  • Loading branch information
messa authored and ShaneHarvey committed Oct 9, 2018
1 parent c80d285 commit 018f1da
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions bson/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ class UUIDLegacy(Binary):
... CodecOptions(uuid_representation=STANDARD))
>>> coll.insert_one({'uuid': Binary(my_uuid.bytes, 3)}).inserted_id
ObjectId('...')
>>> coll.find({'uuid': my_uuid}).count()
>>> coll.count_documents({'uuid': my_uuid})
0
>>> coll.find({'uuid': UUIDLegacy(my_uuid)}).count()
>>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
1
>>> coll.find({'uuid': UUIDLegacy(my_uuid)})[0]['uuid']
UUID('...')
Expand All @@ -209,9 +209,9 @@ class UUIDLegacy(Binary):
>>> doc = coll.find_one({'uuid': UUIDLegacy(my_uuid)})
>>> coll.replace_one({"_id": doc["_id"]}, doc).matched_count
1
>>> coll.find({'uuid': UUIDLegacy(my_uuid)}).count()
>>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
0
>>> coll.find({'uuid': {'$in': [UUIDLegacy(my_uuid), my_uuid]}}).count()
>>> coll.count_documents({'uuid': {'$in': [UUIDLegacy(my_uuid), my_uuid]}})
1
>>> coll.find_one({'uuid': my_uuid})['uuid']
UUID('...')
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/bulk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bulk insert operations.
>>> db = pymongo.MongoClient().bulk_example
>>> db.test.insert_many([{'i': i} for i in range(10000)]).inserted_ids
[...]
>>> db.test.count()
>>> db.test.count_documents({})
10000

Mixed Bulk Write Operations
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,20 @@ author is "Mike":
Counting
--------
If we just want to know how many documents match a query we can
perform a :meth:`~pymongo.cursor.Cursor.count` operation instead of a
full query. We can get a count of all of the documents in a
collection:
perform a :meth:`~pymongo.collection.Collection.count_documents` operation
instead of a full query. We can get a count of all of the documents
in a collection:

.. doctest::

>>> posts.count()
>>> posts.count_documents({})
3

or just of those documents that match a specific query:

.. doctest::

>>> posts.find({"author": "Mike"}).count()
>>> posts.count_documents({"author": "Mike"})
2

Range Queries
Expand Down
20 changes: 10 additions & 10 deletions pymongo/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def insert_one(self, document, bypass_document_validation=False,
session=None):
"""Insert a single document.
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
Expand Down Expand Up @@ -697,12 +697,12 @@ def insert_many(self, documents, ordered=True,
bypass_document_validation=False, session=None):
"""Insert an iterable of documents.
>>> db.test.count()
>>> db.test.count_documents({})
0
>>> result = db.test.insert_many([{'x': i} for i in range(2)])
>>> result.inserted_ids
[ObjectId('54f113fffba522406c9cc20e'), ObjectId('54f113fffba522406c9cc20f')]
>>> db.test.count()
>>> db.test.count_documents({})
2
:Parameters:
Expand Down Expand Up @@ -1156,12 +1156,12 @@ def _delete(session, sock_info, retryable_write):
def delete_one(self, filter, collation=None, session=None):
"""Delete a single document matching the filter.
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
3
>>> result = db.test.delete_one({'x': 1})
>>> result.deleted_count
1
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
2
:Parameters:
Expand Down Expand Up @@ -1194,12 +1194,12 @@ def delete_one(self, filter, collation=None, session=None):
def delete_many(self, filter, collation=None, session=None):
"""Delete one or more documents matching the filter.
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
3
>>> result = db.test.delete_many({'x': 1})
>>> result.deleted_count
3
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
0
:Parameters:
Expand Down Expand Up @@ -2434,7 +2434,7 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
stage and returns a
:class:`~pymongo.change_stream.CollectionChangeStream` cursor which
iterates over changes on this collection.
Introduced in MongoDB 3.6.
.. code-block:: python
Expand Down Expand Up @@ -2875,11 +2875,11 @@ def find_one_and_delete(self, filter,
projection=None, sort=None, session=None, **kwargs):
"""Finds a single document and deletes it, returning the document.
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
2
>>> db.test.find_one_and_delete({'x': 1})
{u'x': 1, u'_id': ObjectId('54f4e12bfba5220aa4d6dee8')}
>>> db.test.count({'x': 1})
>>> db.test.count_documents({'x': 1})
1
If multiple documents match *filter*, a *sort* can be applied.
Expand Down

0 comments on commit 018f1da

Please sign in to comment.