Skip to content

Commit 3e27769

Browse files
committed
Count API updates
count() method deprecated estimatedDocumentCount() methods added documentCount() methods added JAVA-2885
1 parent 193cce8 commit 3e27769

File tree

48 files changed

+1145
-725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1145
-725
lines changed

docs/reference/content/driver-async/getting-started/quick-start-pojo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ List<Person> people = asList(
214214
collection.insertMany(people, new SingleResultCallback<Void>() {
215215
@Override
216216
public void onResult(final Void result, final Throwable t) {
217-
collection.count(new SingleResultCallback<Long>() {
217+
collection.countDocuments(new SingleResultCallback<Long>() {
218218
@Override
219219
public void onResult(final Long count, final Throwable t) {
220220
System.out.println("total # of people " + count);

docs/reference/content/driver-async/getting-started/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ To count the number of documents in a collection, you can use the collection's [
268268
method. The following code should print `101` (the 100 inserted via `insertMany` plus the 1 inserted via the `insertOne`).
269269

270270
```java
271-
collection.count(
271+
collection.countDocuments(
272272
new SingleResultCallback<Long>() {
273273
@Override
274274
public void onResult(final Long count, final Throwable t) {

docs/reference/content/driver-async/reference/observables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ In the following example we print out the count of the number of documents in a
7979
Block<SingleResultCallback<Long>> operation = new Block<SingleResultCallback<Long>>() {
8080
@Override
8181
void apply(final SingleResultCallback<Long> callback) {
82-
collection.count(callback);
82+
collection.countDocuments(callback);
8383
}
8484
};
8585

8686
// Or in Java 8 syntax:
87-
operation = (Block<SingleResultCallback<Long>>) collection::count;
87+
operation = (Block<SingleResultCallback<Long>>) collection::countDocuments;
8888

8989
Observables.observe(operation).subscribe(new Observer<Long>(){
9090
@Override

docs/reference/content/driver-async/tutorials/text-search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ To perform text search, use the [`Filters.text()`]({{<apiref "com/mongodb/client
7979
For example, the following code performs a text search on the `name` field for the word `"bakery"` or `"coffee"`.
8080

8181
```java
82-
collection.count(Filters.text("bakery coffee"), new SingleResultCallback<Long>() {
82+
collection.countDocuments(Filters.text("bakery coffee"), new SingleResultCallback<Long>() {
8383
@Override
8484
public void onResult(final Long count, final Throwable t) {
8585
System.out.println("Text search matches: " +count);
@@ -119,7 +119,7 @@ The [`Filters.text()`]({{<apiref "com/mongodb/client/model/Filters.html#text-ja
119119
For example, the following text search specifies the [text search language]({{<docsref "reference/text-search-languages">}}) option when performing text search for the word `cafe`:
120120

121121
```java
122-
collection.count(Filters.text("cafe",
122+
collection.countDocuments(Filters.text("cafe",
123123
new TextSearchOptions().language("english")),
124124
new SingleResultCallback<Long>() {
125125
@Override

docs/reference/content/driver/getting-started/quick-start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ If no top-level `_id` field is specified in the document, MongoDB automatically
262262

263263
## Count Documents in A Collection
264264

265-
To count the number of documents in a collection, you can use the collection's [`count()`]({{< apiref "com/mongodb/client/MongoCollection#count--">}})
265+
To count the number of documents in a collection, you can use the collection's [`countDocuments()`]({{< apiref "com/mongodb/client/MongoCollection#countDocuments--">}})
266266
method. The following code should print `101` (the 100 inserted via `insertMany` plus the 1 inserted via the `insertOne`).
267267

268268
```java
269-
System.out.println(collection.count());
269+
System.out.println(collection.countDocuments());
270270
```
271271

272272
## Query the Collection

docs/reference/content/driver/tutorials/text-search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ To perform text search, use the [`Filters.text()`]({{<apiref "com/mongodb/client
7878
For example, the following code performs a text search on the `name` field for the word `"bakery"` or `"coffee"`.
7979

8080
```java
81-
long matchCount = collection.count(Filters.text("bakery coffee"));
81+
long matchCount = collection.countDocuments(Filters.text("bakery coffee"));
8282
System.out.println("Text search matches: " + matchCount);
8383
```
8484

@@ -112,7 +112,7 @@ The [`Filters.text()`]({{<apiref "com/mongodb/client/model/Filters.html#text-ja
112112
For example, the following text search specifies the [text search language]({{<docsref "reference/text-search-languages">}}) option when performing text search for the word `cafe`:
113113

114114
```java
115-
long matchCountEnglish = collection.count(Filters.text("cafe", new TextSearchOptions().language("english")));
115+
long matchCountEnglish = collection.countDocuments(Filters.text("cafe", new TextSearchOptions().language("english")));
116116
System.out.println("Text search matches (english): " + matchCountEnglish);
117117
```
118118

driver-async/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Example for Maven:
107107
final CountDownLatch countLatch = new CountDownLatch(1);
108108
final AtomicLong count = new AtomicLong();
109109
System.out.println("Counting the number of documents");
110-
collection.count(new SingleResultCallback<Long>() {
110+
collection.countDocuments(new SingleResultCallback<Long>() {
111111
@Override
112112
public void onResult(final Long result, final Throwable t) {
113113
count.set(result);

driver-async/src/examples/documentation/DocumentationSamples.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void onResult(final Void result, final Throwable t) {
162162
// End Example 3
163163

164164
final CountDownLatch check2 = new CountDownLatch(1);
165-
collection.count(new SingleResultCallback<Long>() {
165+
collection.countDocuments(new SingleResultCallback<Long>() {
166166
@Override
167167
public void onResult(final Long result, final Throwable t) {
168168
assertEquals(Long.valueOf(4), result);
@@ -194,7 +194,7 @@ public void onResult(final Void result, final Throwable t) {
194194
// End Example 6
195195

196196
final CountDownLatch check1 = new CountDownLatch(1);
197-
collection.count(new SingleResultCallback<Long>() {
197+
collection.countDocuments(new SingleResultCallback<Long>() {
198198
@Override
199199
public void onResult(final Long result, final Throwable t) {
200200
assertEquals(Long.valueOf(5), result);
@@ -327,7 +327,7 @@ public void onResult(final Void result, final Throwable t) {
327327
// End Example 14
328328

329329
final CountDownLatch check1 = new CountDownLatch(1);
330-
collection.count(new SingleResultCallback<Long>() {
330+
collection.countDocuments(new SingleResultCallback<Long>() {
331331
@Override
332332
public void onResult(final Long result, final Throwable t) {
333333
assertEquals(Long.valueOf(5), result);
@@ -434,7 +434,7 @@ public void onResult(final Void result, final Throwable t) {
434434
// End Example 20
435435

436436
final CountDownLatch check1 = new CountDownLatch(1);
437-
collection.count(new SingleResultCallback<Long>() {
437+
collection.countDocuments(new SingleResultCallback<Long>() {
438438
@Override
439439
public void onResult(final Long result, final Throwable t) {
440440
assertEquals(Long.valueOf(5), result);
@@ -553,7 +553,7 @@ public void onResult(final Void result, final Throwable t) {
553553
// End Example 29
554554

555555
FutureResultCallback<Long> assertCountFuture = new FutureResultCallback<Long>();
556-
collection.count(assertCountFuture);
556+
collection.countDocuments(assertCountFuture);
557557
assertEquals(Long.valueOf(5), assertCountFuture.get(10, TimeUnit.SECONDS));
558558

559559
//Start Example 30
@@ -664,7 +664,7 @@ public void onResult(final Void result, final Throwable t) {
664664
// End Example 38
665665

666666
FutureResultCallback<Long> assertCountFuture = new FutureResultCallback<Long>();
667-
collection.count(assertCountFuture);
667+
collection.countDocuments(assertCountFuture);
668668
assertEquals(Long.valueOf(2), assertCountFuture.get(10, TimeUnit.SECONDS));
669669

670670
//Start Example 39
@@ -725,7 +725,7 @@ public void onResult(final Void result, final Throwable t) {
725725
// End Example 42
726726

727727
final CountDownLatch check1 = new CountDownLatch(1);
728-
collection.count(new SingleResultCallback<Long>() {
728+
collection.countDocuments(new SingleResultCallback<Long>() {
729729
@Override
730730
public void onResult(final Long result, final Throwable t) {
731731
assertEquals(Long.valueOf(5), result);
@@ -879,7 +879,7 @@ public void onResult(final Void result, final Throwable t) {
879879
// End Example 51
880880

881881
FutureResultCallback<Long> check1 = new FutureResultCallback<Long>();
882-
collection.count(check1);
882+
collection.countDocuments(check1);
883883
assertEquals(Long.valueOf(10), check1.get(10, TimeUnit.SECONDS));
884884

885885
//Start Example 52
@@ -976,7 +976,7 @@ public void onResult(final Void result, final Throwable t) {
976976
// End Example 55
977977

978978
FutureResultCallback<Long> check1 = new FutureResultCallback<Long>();
979-
collection.count(check1);
979+
collection.countDocuments(check1);
980980
assertEquals(Long.valueOf(5), check1.get(10, TimeUnit.SECONDS));
981981

982982
//Start Example 57
@@ -991,7 +991,7 @@ public void onResult(final DeleteResult result, final Throwable t) {
991991
//End Example 57
992992

993993
FutureResultCallback<Long> check2 = new FutureResultCallback<Long>();
994-
collection.count(check2);
994+
collection.countDocuments(check2);
995995
assertEquals(Long.valueOf(2), check2.get(10, TimeUnit.SECONDS));
996996

997997
//Start Example 58
@@ -1006,7 +1006,7 @@ public void onResult(final DeleteResult result, final Throwable t) {
10061006
//End Example 58
10071007

10081008
FutureResultCallback<Long> check3 = new FutureResultCallback<Long>();
1009-
collection.count(check3);
1009+
collection.countDocuments(check3);
10101010
assertEquals(Long.valueOf(1), check3.get(10, TimeUnit.SECONDS));
10111011

10121012
//Start Example 56
@@ -1021,7 +1021,7 @@ public void onResult(final DeleteResult result, final Throwable t) {
10211021
//End Example 56
10221022

10231023
FutureResultCallback<Long> check4 = new FutureResultCallback<Long>();
1024-
collection.count(check4);
1024+
collection.countDocuments(check4);
10251025
assertEquals(Long.valueOf(0), check4.get(10, TimeUnit.SECONDS));
10261026
}
10271027

driver-async/src/examples/tour/PojoQuickTour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void onResult(final Person person, final Throwable t) {
108108
collection.insertMany(people, new SingleResultCallback<Void>() {
109109
@Override
110110
public void onResult(final Void result, final Throwable t) {
111-
collection.count(new SingleResultCallback<Long>() {
111+
collection.countDocuments(new SingleResultCallback<Long>() {
112112
@Override
113113
public void onResult(final Long count, final Throwable t) {
114114
System.out.println("total # of people " + count);

driver-async/src/examples/tour/QuickTour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void onResult(final Document document, final Throwable t) {
123123
collection.insertMany(documents, new SingleResultCallback<Void>() {
124124
@Override
125125
public void onResult(final Void result, final Throwable t) {
126-
collection.count(new SingleResultCallback<Long>() {
126+
collection.countDocuments(new SingleResultCallback<Long>() {
127127
@Override
128128
public void onResult(final Long count, final Throwable t) {
129129
System.out.println("total # of documents after inserting 100 small ones (should be 101) " + count);

0 commit comments

Comments
 (0)