Skip to content

Commit 5769617

Browse files
(DOCS-15142): Add inaccurate count warning for fcbis (#1189)
* (DOCS-15142): Add inaccurate count warning for fcbis * update count method page * refactor count method page * formatting * add ref and link * update count method page * tweaks
1 parent cd87997 commit 5769617

File tree

4 files changed

+80
-62
lines changed

4 files changed

+80
-62
lines changed

source/core/replica-set-sync.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ based*.
4141
Logical Initial Sync Process
4242
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4343

44-
When you perform a
45-
:ref:`logical initial sync <replica-set-initial-sync-logical>`, MongoDB:
44+
When you perform a logical initial sync, MongoDB:
4645

4746
#. Clones all databases except the :ref:`local
4847
<replica-set-local-database>` database. To clone, the
@@ -72,15 +71,25 @@ To perform an initial sync, see
7271
File Copy Based Initial Sync
7372
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7473

75-
:ref:`File copy based initial sync
76-
<replica-set-initial-sync-file-copy-based>` runs the initial sync
77-
process by copying and moving files on the file system.
74+
File copy based initial sync runs the initial sync process by copying
75+
and moving files on the file system.
7876

7977
File copy based initial sync can be faster than
8078
:ref:`logical initial sync <replica-set-initial-sync-logical>`.
8179

8280
It is only available on Enterprise Server.
8381

82+
.. important:: File copy based initial sync may cause inaccurate counts
83+
84+
After file copy based initial sync completes, if you run the
85+
:method:`~db.collection.count()` method without a query predicate, the
86+
count of documents returned may be inaccurate.
87+
88+
A ``count`` method without a query predicate looks like this:
89+
``db.<collection>.count()``.
90+
91+
To learn more, see :ref:`count-method-behavior-query-predicate`.
92+
8493
Limitations
8594
```````````
8695

source/reference/command/count.txt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,6 @@ Command Fields
146146
- :method:`db.collection.estimatedDocumentCount()`
147147
- :method:`db.collection.count()`
148148

149-
.. important::
150-
151-
- Avoid using the :dbcommand:`count` and its wrapper methods
152-
without a query predicate (note:
153-
:method:`db.collection.estimatedDocumentCount()` does not take
154-
a query predicate) since without the query predicate, these
155-
operations return results based on the collection's metadata,
156-
which may result in an approximate count. In particular,
157-
158-
- On a sharded cluster, the resulting count will not correctly
159-
filter out :term:`orphaned documents <orphaned document>`.
160-
161-
- :ref:`After an unclean shutdown <count-accuracy-shutdown>`,
162-
the count may be incorrect.
163-
164-
- For counts based on collection metadata, see also
165-
:ref:`collStats pipeline stage with the count <collstat-count>`
166-
option.
167-
168149
Stable API Support
169150
------------------
170151

@@ -176,6 +157,27 @@ MongoDB 6.0 or greater.
176157
Behavior
177158
--------
178159

160+
.. _count-command-behavior-query-predicate:
161+
162+
Inaccurate Counts Without Query Predicate
163+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164+
165+
When you call :dbcommand:`count` without a query predicate, you may
166+
receive inaccurate document counts. Without a query predicate,
167+
:dbcommand:`count` commands return results based on the collection's
168+
metadata, which may result in an approximate count. In particular,
169+
170+
- On a sharded cluster, the resulting count will not correctly
171+
filter out :term:`orphaned documents <orphaned document>`.
172+
173+
- After an unclean shutdown or :ref:`file copy based initial sync
174+
<replica-set-initial-sync-file-copy-based>`, the count may be
175+
incorrect.
176+
177+
For counts based on collection metadata, see also
178+
:ref:`collStats pipeline stage with the count <collstat-count>`
179+
option.
180+
179181
Count and Transactions
180182
~~~~~~~~~~~~~~~~~~~~~~
181183

source/reference/method/cursor.count.txt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ Definition
3333
matching documents. The operation does not perform the query but
3434
instead counts the results that would be returned by the query.
3535

36-
.. important::
37-
38-
- Avoid using :method:`~cursor.count()` if the
39-
:method:`~db.collection.find()` operation is run without a
40-
query predicate since without the query predicate, these
41-
:method:`~cursor.count()` returns results based on the
42-
collection's metadata, which may result in an approximate
43-
count. In particular,
44-
45-
- On a sharded cluster, the resulting count will not correctly
46-
filter out :term:`orphaned documents <orphaned document>`.
47-
48-
- After an unclean shutdown, the count may be
49-
incorrect.
50-
51-
- For counts based on collection metadata, see also
52-
:ref:`collStats pipeline stage with the count <collstat-count>`
53-
option.
54-
5536

5637
The :method:`~cursor.count()` method has the following
5738
prototype form:
@@ -105,6 +86,29 @@ Definition
10586
Behavior
10687
--------
10788

89+
.. _count-cursor-behavior-query-predicate:
90+
91+
Inaccurate Counts Without Query Predicate
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
94+
When you call :method:`~cursor.count()` on a
95+
:method:`~db.collection.find()` operation which does not specify a query
96+
predicate, the :method:`~cursor.count()` method can return inaccurate
97+
document counts. These :method:`~cursor.count()` methods return results
98+
based on the collection's metadata, which may result in an approximate
99+
count. In particular,
100+
101+
- On a sharded cluster, the resulting count will not correctly
102+
filter out :term:`orphaned documents <orphaned document>`.
103+
104+
- After an unclean shutdown or :ref:`file copy based initial sync
105+
<replica-set-initial-sync-file-copy-based>`, the count may be
106+
incorrect.
107+
108+
For counts based on collection metadata, see also
109+
:ref:`collStats pipeline stage with the count <collstat-count>`
110+
option.
111+
108112
Count and Transactions
109113
~~~~~~~~~~~~~~~~~~~~~~
110114

source/reference/method/db.collection.count.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ Definition
3333
:method:`~db.collection.find()` operation but instead counts and
3434
returns the number of results that match a query.
3535

36-
.. important::
37-
38-
- Avoid using the :method:`db.collection.count()` method without
39-
a query predicate since without the query predicate, the method
40-
returns results based on the collection's metadata, which may
41-
result in an approximate count. In particular,
42-
43-
- On a sharded cluster, the resulting count will not correctly
44-
filter out :term:`orphaned documents <orphaned document>`.
45-
46-
- :ref:`After an unclean shutdown
47-
<collection-count-accuracy-shutdown>`, the count may be
48-
incorrect.
49-
50-
- For counts based on collection metadata, see also
51-
:ref:`collStats pipeline stage with the count <collstat-count>`
52-
option.
53-
54-
5536
.. list-table::
5637
:header-rows: 1
5738
:widths: 20 20 80
@@ -162,6 +143,28 @@ Definition
162143
Behavior
163144
--------
164145

146+
.. _count-method-behavior-query-predicate:
147+
148+
Inaccurate Counts Without Query Predicate
149+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150+
151+
When you call :method:`~db.collection.count()` without a query
152+
predicate, you may receive inaccurate document counts. Without a query
153+
predicate, :method:`~db.collection.count()` methods return results based
154+
on the collection's metadata, which may result in an approximate count.
155+
In particular,
156+
157+
- On a sharded cluster, the resulting count will not correctly
158+
filter out :term:`orphaned documents <orphaned document>`.
159+
160+
- After an unclean shutdown or :ref:`file copy based initial sync
161+
<replica-set-initial-sync-file-copy-based>`, the count may be
162+
incorrect.
163+
164+
For counts based on collection metadata, see also
165+
:ref:`collStats pipeline stage with the count <collstat-count>`
166+
option.
167+
165168
Count and Transactions
166169
~~~~~~~~~~~~~~~~~~~~~~
167170

0 commit comments

Comments
 (0)