|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.vz.mongodb.jackson.DBQuery.AbstractBuilder<DBCursor<T>>
net.vz.mongodb.jackson.DBCursor<T>
public class DBCursor<T>
An iterator over database results.
Doing a find()
query on a collection returns a
DBCursor
thus
DBCursor cursor = collection.find( query ); if( cursor.hasNext() ) T 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();
Field Summary |
---|
Fields inherited from class net.vz.mongodb.jackson.DBQuery.AbstractBuilder |
---|
query |
Constructor Summary | |
---|---|
DBCursor(JacksonDBCollection<T,?> jacksonDBCollection,
com.mongodb.DBCursor cursor)
|
Method Summary | |
---|---|
DBCursor<T> |
addOption(int option)
adds a query option - see Bytes.QUERYOPTION_* for simpleList |
DBCursor<T> |
addSpecial(String name,
Object o)
adds a special operator like $maxScan or $returnKey e.g. |
DBCursor<T> |
batchSize(int n)
Limits the number of elements returned in one batch. |
void |
close()
kills the current cursor on the server. |
DBCursor<T> |
copy()
Creates a copy of an existing database cursor. |
int |
count()
Counts the number of objects matching the query This does not take limit/skip into consideration |
T |
curr()
Returns the element the cursor is at. |
com.mongodb.DBObject |
explain()
Returns an object containing basic information about the execution 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 |
JacksonDBCollection |
getCollection()
gets the collection |
com.mongodb.DBCursor |
getCursor()
Get the underlying MongoDB cursor. |
long |
getCursorId()
gets the cursor id. |
com.mongodb.DBDecoderFactory |
getDecoderFactory()
|
com.mongodb.DBObject |
getKeysWanted()
gets the fields to be returned |
int |
getOptions()
gets the query options |
com.mongodb.DBObject |
getQuery()
gets the query |
com.mongodb.ReadPreference |
getReadPreference()
Gets the default read preference |
com.mongodb.ServerAddress |
getServerAddress()
Gets the Server Address of the server that data is pulled from. |
List<Integer> |
getSizes()
gets a simpleList containing the number of items received in each batch |
boolean |
hasNext()
Checks if there is another object available |
DBCursor<T> |
hint(com.mongodb.DBObject indexKeys)
Informs the database of indexed fields of the collection in order to improve performance. |
DBCursor<T> |
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<T> |
iterator()
creates a copy of this cursor object that can be iterated. |
int |
length()
pulls back all items into an array and returns the number of objects. |
DBCursor<T> |
limit(int n)
Limits the number of elements returned. |
T |
next()
Returns the object the cursor is at and moves the cursor ahead by one. |
int |
numGetMores()
gets the number of times, so far, that the cursor retrieved a batch from the database |
int |
numSeen()
Returns the number of objects through which the cursor has iterated. |
protected DBCursor<T> |
put(String field,
String op,
Object value)
|
protected DBCursor<T> |
putGroup(String op,
Object... expressions)
|
void |
remove()
Not implemented. |
DBCursor<T> |
resetOptions()
resets the query options |
DBCursor<T> |
setDecoderFactory(com.mongodb.DBDecoderFactory fact)
|
DBCursor<T> |
setOptions(int options)
sets the query option - see Bytes.QUERYOPTION_* for simpleList |
DBCursor<T> |
setReadPreference(com.mongodb.ReadPreference preference)
Sets the read preference for this cursor. |
int |
size()
Counts the number of objects matching the query this does take limit/skip into consideration |
DBCursor<T> |
skip(int n)
Discards a given number of elements at the beginning of the cursor. |
DBCursor<T> |
snapshot()
Use snapshot mode for the query. |
DBCursor<T> |
sort(com.mongodb.DBObject orderBy)
Sorts this cursor'string elements. |
List<T> |
toArray()
Converts this cursor to an array. |
List<T> |
toArray(int max)
Converts this cursor to an array. |
Methods inherited from class net.vz.mongodb.jackson.DBQuery.AbstractBuilder |
---|
all, all, and, elemMatch, exists, greaterThan, greaterThanEquals, in, in, is, lessThan, lessThanEquals, mod, nor, notEquals, notExists, notIn, notIn, or, regex, size, where |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DBCursor(JacksonDBCollection<T,?> jacksonDBCollection, com.mongodb.DBCursor cursor)
Method Detail |
---|
public DBCursor<T> copy()
public Iterator<T> iterator()
iterator
in interface Iterable<T>
public DBCursor<T> sort(com.mongodb.DBObject orderBy)
orderBy
- the fields by which to sort
public DBCursor<T> addSpecial(String name, Object o)
name
- The nameo
- The object
public DBCursor<T> hint(com.mongodb.DBObject indexKeys)
indexKeys
- a DBObject
with fields and direction
public DBCursor<T> hint(String indexName)
indexName
- the name of an index
public DBCursor<T> snapshot()
public com.mongodb.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<T> limit(int n)
#batchSize(int)
which is the preferred method.
n
- the number of elements to return
public DBCursor<T> batchSize(int n)
n
- the number of elements to return in a batch
public DBCursor<T> skip(int n)
n
- the number of elements to skip
RuntimeException
- if the cursor has started to be iterated throughpublic long getCursorId()
public void close()
public DBCursor<T> addOption(int option)
option
- The option
public DBCursor<T> setOptions(int options)
options
- The options
public DBCursor<T> resetOptions()
public int getOptions()
public int numGetMores()
public List<Integer> getSizes()
public int numSeen()
public boolean hasNext() throws com.mongodb.MongoException
hasNext
in interface Iterator<T>
com.mongodb.MongoException
public T next() throws com.mongodb.MongoException
next
in interface Iterator<T>
com.mongodb.MongoException
public T curr()
public void remove()
remove
in interface Iterator<T>
public int length() throws com.mongodb.MongoException
com.mongodb.MongoException
- Ig as error occurredcount()
,
size()
public List<T> toArray() throws com.mongodb.MongoException
com.mongodb.MongoException
- If an error occurredpublic List<T> toArray(int max) throws com.mongodb.MongoException
max
- the maximum number of objects to return
com.mongodb.MongoException
- If an error occurredpublic int itcount()
count()
public int count()
com.mongodb.MongoException
size()
public int size()
com.mongodb.MongoException
count()
public com.mongodb.DBObject getKeysWanted()
public com.mongodb.DBObject getQuery()
public JacksonDBCollection getCollection()
public com.mongodb.ServerAddress getServerAddress()
public DBCursor<T> setReadPreference(com.mongodb.ReadPreference preference)
ReadPreference
for more information.
preference
- Read Preference to use
public com.mongodb.ReadPreference getReadPreference()
public DBCursor<T> setDecoderFactory(com.mongodb.DBDecoderFactory fact)
public com.mongodb.DBDecoderFactory getDecoderFactory()
public com.mongodb.DBCursor getCursor()
protected DBCursor<T> put(String field, String op, Object value)
put
in class DBQuery.AbstractBuilder<DBCursor<T>>
protected DBCursor<T> putGroup(String op, Object... expressions)
putGroup
in class DBQuery.AbstractBuilder<DBCursor<T>>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |