PYTHON-1642 - Replace count() with count_documents({}) in docs (#376)

This commit is contained in:
Petr Messner 2018-09-08 20:24:57 +02:00 committed by Shane Harvey
parent bc26c0db69
commit 7f1939ebcb
4 changed files with 20 additions and 20 deletions

View File

@ -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('...')
@ -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('...')

View File

@ -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

View File

@ -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

View File

@ -647,7 +647,7 @@ class Collection(common.BaseObject):
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
@ -697,12 +697,12 @@ class Collection(common.BaseObject):
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:
@ -1156,12 +1156,12 @@ class Collection(common.BaseObject):
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:
@ -1194,12 +1194,12 @@ class Collection(common.BaseObject):
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:
@ -2434,7 +2434,7 @@ class Collection(common.BaseObject):
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
@ -2875,11 +2875,11 @@ class Collection(common.BaseObject):
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.