Skip to content

Commit 715e00e

Browse files
DOCSP-19389 available method (#175)
* added available method
1 parent d9bd99d commit 715e00e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

source/fundamentals/crud/read-operations/cursor.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ results:
5858
This method is often used when your query filter will match one
5959
document, such as when filtering by a unique index.
6060

61+
Number of Results
62+
~~~~~~~~~~~~~~~~~
63+
64+
Use the ``available()`` method to retrieve the number of results
65+
locally present without blocking:
66+
67+
.. literalinclude:: /includes/fundamentals/code-snippets/Cursor.java
68+
:language: java
69+
:dedent:
70+
:start-after: begin availableExample
71+
:end-before: end availableExample
72+
73+
The method returns ``0`` if the application has already iterated though
74+
all the documents in the cursor or if the cursor is closed.
75+
6176
Into
6277
~~~~
6378

@@ -124,6 +139,7 @@ For more information about the methods and classes mentioned in this section,
124139
see the following API Documentation:
125140

126141
- `first() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#first()>`__
142+
- `available() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCursor.html#available()>`__
127143
- `into() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#into(A)>`__
128144
- `cursor() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#cursor()>`__
129145
- `explain() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/FindIterable.html#explain()>`__

source/includes/fundamentals/code-snippets/Cursor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static void main(String [] args){
3939
System.out.println("First Example");
4040
c.firstExample();
4141

42+
System.out.println("Available Example");
43+
c.availableExample();
44+
4245
System.out.println("Explain Example");
4346
c.explainExample();
4447

@@ -69,6 +72,13 @@ private void firstExample(){
6972
// end firstExample
7073
}
7174

75+
private void availableExample(){
76+
// begin availableExample
77+
MongoCursor<Document> cursor = collection.find().cursor();
78+
System.out.println(cursor.available());
79+
// end availableExample
80+
}
81+
7282
private void explainExample(){
7383
// begin explainExample
7484
Document explanation = collection.find().explain(ExplainVerbosity.EXECUTION_STATS);

0 commit comments

Comments
 (0)