|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mongodb.DBCursor
public class DBCursor
An iterator over database results.
Doing a find()
query on a collection returns a
DBCursor
thus
DBCursor cursor = collection.find( query ); if( cursor.hasNext() ) DBObject obj = cursor.next();
Warning: Calling toArray
or length
on
a DBCursor will irrevocably turn it into an array. This
means that, if the cursor was iterating over ten million results
(which it was lazily fetching from the database), suddenly there will
be a ten-million element array in memory. Before converting to an array,
make sure that there are a reasonable number of results using
skip()
and limit()
.
For example, to get an array of the 1000-1100th elements of a cursor, use
Listobj = collection.find( query ).skip( 1000 ).limit( 100 ).toArray();
Constructor Summary | |
---|---|
DBCursor(DBCollection collection,
DBObject q,
DBObject k)
Initializes a new database cursor |
Method Summary | |
---|---|
DBCursor |
addOption(int option)
adds an option - see Bytes.QUERYOPTION_* for list |
DBCursor |
batchSize(int n)
Limits the number of elements returned in one batch |
DBCursor |
copy()
Creates a copy of an existing database cursor. |
int |
count()
Counts the number of elements in this cursor. |
DBObject |
curr()
Returns the element the cursor is at. |
DBObject |
explain()
Returns an object containing basic information about the exectution of the query that created this cursor This creates a DBObject with the key/value pairs:
"cursor" : cursor type
"nScanned" : number of records examined by the database for this query
"n" : the number of records that the database returned
"millis" : how long it took the database to execute the query |
DBObject |
getKeysWanted()
|
DBObject |
getQuery()
|
List<Integer> |
getSizes()
|
boolean |
hasNext()
Checks if there is another element. |
DBCursor |
hint(DBObject indexKeys)
Informs the database of indexed fields of the collection in order to improve performance. |
DBCursor |
hint(String indexName)
Informs the database of an indexed field of the collection in order to improve performance. |
int |
itcount()
for testing only! iterates cursor and counts objects |
Iterator<DBObject> |
iterator()
|
int |
length()
Finds the number of elements in the array. |
DBCursor |
limit(int n)
Limits the number of elements returned. |
DBObject |
next()
Returns the element the cursor is at and moves the cursor ahead by one. |
int |
numGetMores()
|
int |
numSeen()
Returns the number of objects through which the cursor has iterated. |
void |
remove()
Unimplemented. |
DBCursor |
skip(int n)
Discards a given number of elements at the beginning of the cursor. |
DBCursor |
snapshot()
Use snapshot mode for the query. |
DBCursor |
sort(DBObject orderBy)
Sorts this cursor's elements. |
List<DBObject> |
toArray()
Converts this cursor to an array. |
List<DBObject> |
toArray(int min)
Converts this cursor to an array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DBCursor(DBCollection collection, DBObject q, DBObject k)
collection
- collection to useq
- query to performk
- keys to return from the queryMethod Detail |
---|
public DBCursor copy()
public Iterator<DBObject> iterator()
iterator
in interface Iterable<DBObject>
public DBCursor sort(DBObject orderBy)
orderBy
- the fields on which to sort
public DBCursor hint(DBObject indexKeys)
indexKeys
- an DBObject
with index names as keys
public DBCursor snapshot()
public DBCursor hint(String indexName)
indexName
- the name of an index
public DBObject explain()
DBObject
with the key/value pairs:
"cursor" : cursor type
"nScanned" : number of records examined by the database for this query
"n" : the number of records that the database returned
"millis" : how long it took the database to execute the query
DBObject
public DBCursor limit(int n)
n
- the number of elements to return
public DBCursor batchSize(int n)
n
- the number of elements to return in a batchpublic DBCursor skip(int n)
n
- the number of elements to skip
RuntimeException
- if the cursor has started to be iterated throughpublic DBCursor addOption(int option)
public int numGetMores()
public List<Integer> getSizes()
public int numSeen()
public boolean hasNext()
hasNext
in interface Iterator<DBObject>
public DBObject next()
next
in interface Iterator<DBObject>
public DBObject curr()
public void remove()
remove
in interface Iterator<DBObject>
public int length() throws MongoException
MongoException
public List<DBObject> toArray() throws MongoException
MongoException
public List<DBObject> toArray(int min) throws MongoException
min
- the minimum size of the array to return
MongoException
public int itcount()
public int count() throws MongoException
MongoException
public DBObject getKeysWanted()
public DBObject getQuery()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |