Skip to content

Commit 7f1939e

Browse files
messaShaneHarvey
authored andcommitted
PYTHON-1642 - Replace count() with count_documents({}) in docs (mongodb#376)
1 parent bc26c0d commit 7f1939e

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

bson/binary.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ class UUIDLegacy(Binary):
198198
... CodecOptions(uuid_representation=STANDARD))
199199
>>> coll.insert_one({'uuid': Binary(my_uuid.bytes, 3)}).inserted_id
200200
ObjectId('...')
201-
>>> coll.find({'uuid': my_uuid}).count()
201+
>>> coll.count_documents({'uuid': my_uuid})
202202
0
203-
>>> coll.find({'uuid': UUIDLegacy(my_uuid)}).count()
203+
>>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
204204
1
205205
>>> coll.find({'uuid': UUIDLegacy(my_uuid)})[0]['uuid']
206206
UUID('...')
@@ -209,9 +209,9 @@ class UUIDLegacy(Binary):
209209
>>> doc = coll.find_one({'uuid': UUIDLegacy(my_uuid)})
210210
>>> coll.replace_one({"_id": doc["_id"]}, doc).matched_count
211211
1
212-
>>> coll.find({'uuid': UUIDLegacy(my_uuid)}).count()
212+
>>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
213213
0
214-
>>> coll.find({'uuid': {'$in': [UUIDLegacy(my_uuid), my_uuid]}}).count()
214+
>>> coll.count_documents({'uuid': {'$in': [UUIDLegacy(my_uuid), my_uuid]}})
215215
1
216216
>>> coll.find_one({'uuid': my_uuid})['uuid']
217217
UUID('...')

doc/examples/bulk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bulk insert operations.
2929
>>> db = pymongo.MongoClient().bulk_example
3030
>>> db.test.insert_many([{'i': i} for i in range(10000)]).inserted_ids
3131
[...]
32-
>>> db.test.count()
32+
>>> db.test.count_documents({})
3333
10000
3434

3535
Mixed Bulk Write Operations

doc/tutorial.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,20 @@ author is "Mike":
333333
Counting
334334
--------
335335
If we just want to know how many documents match a query we can
336-
perform a :meth:`~pymongo.cursor.Cursor.count` operation instead of a
337-
full query. We can get a count of all of the documents in a
338-
collection:
336+
perform a :meth:`~pymongo.collection.Collection.count_documents` operation
337+
instead of a full query. We can get a count of all of the documents
338+
in a collection:
339339

340340
.. doctest::
341341

342-
>>> posts.count()
342+
>>> posts.count_documents({})
343343
3
344344

345345
or just of those documents that match a specific query:
346346

347347
.. doctest::
348348

349-
>>> posts.find({"author": "Mike"}).count()
349+
>>> posts.count_documents({"author": "Mike"})
350350
2
351351

352352
Range Queries

pymongo/collection.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def insert_one(self, document, bypass_document_validation=False,
647647
session=None):
648648
"""Insert a single document.
649649
650-
>>> db.test.count({'x': 1})
650+
>>> db.test.count_documents({'x': 1})
651651
0
652652
>>> result = db.test.insert_one({'x': 1})
653653
>>> result.inserted_id
@@ -697,12 +697,12 @@ def insert_many(self, documents, ordered=True,
697697
bypass_document_validation=False, session=None):
698698
"""Insert an iterable of documents.
699699
700-
>>> db.test.count()
700+
>>> db.test.count_documents({})
701701
0
702702
>>> result = db.test.insert_many([{'x': i} for i in range(2)])
703703
>>> result.inserted_ids
704704
[ObjectId('54f113fffba522406c9cc20e'), ObjectId('54f113fffba522406c9cc20f')]
705-
>>> db.test.count()
705+
>>> db.test.count_documents({})
706706
2
707707
708708
:Parameters:
@@ -1156,12 +1156,12 @@ def _delete(session, sock_info, retryable_write):
11561156
def delete_one(self, filter, collation=None, session=None):
11571157
"""Delete a single document matching the filter.
11581158
1159-
>>> db.test.count({'x': 1})
1159+
>>> db.test.count_documents({'x': 1})
11601160
3
11611161
>>> result = db.test.delete_one({'x': 1})
11621162
>>> result.deleted_count
11631163
1
1164-
>>> db.test.count({'x': 1})
1164+
>>> db.test.count_documents({'x': 1})
11651165
2
11661166
11671167
:Parameters:
@@ -1194,12 +1194,12 @@ def delete_one(self, filter, collation=None, session=None):
11941194
def delete_many(self, filter, collation=None, session=None):
11951195
"""Delete one or more documents matching the filter.
11961196
1197-
>>> db.test.count({'x': 1})
1197+
>>> db.test.count_documents({'x': 1})
11981198
3
11991199
>>> result = db.test.delete_many({'x': 1})
12001200
>>> result.deleted_count
12011201
3
1202-
>>> db.test.count({'x': 1})
1202+
>>> db.test.count_documents({'x': 1})
12031203
0
12041204
12051205
:Parameters:
@@ -2434,7 +2434,7 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
24342434
stage and returns a
24352435
:class:`~pymongo.change_stream.CollectionChangeStream` cursor which
24362436
iterates over changes on this collection.
2437-
2437+
24382438
Introduced in MongoDB 3.6.
24392439
24402440
.. code-block:: python
@@ -2875,11 +2875,11 @@ def find_one_and_delete(self, filter,
28752875
projection=None, sort=None, session=None, **kwargs):
28762876
"""Finds a single document and deletes it, returning the document.
28772877
2878-
>>> db.test.count({'x': 1})
2878+
>>> db.test.count_documents({'x': 1})
28792879
2
28802880
>>> db.test.find_one_and_delete({'x': 1})
28812881
{u'x': 1, u'_id': ObjectId('54f4e12bfba5220aa4d6dee8')}
2882-
>>> db.test.count({'x': 1})
2882+
>>> db.test.count_documents({'x': 1})
28832883
1
28842884
28852885
If multiple documents match *filter*, a *sort* can be applied.

0 commit comments

Comments
 (0)