SparkMongoCursor

An iterator over database results. Doing a find() query on a collection returns a SparkMongoCursor thus:

var cursor = collection.find( query );
if( cursor.hasNext() )
{var obj = cursor.next();}

limit

signature limit(number count)

returns SparkMongoCursor

Limits the number of elements returned.

params

count - the limit to set

example

var cursor = collection.find( query ).skip( 1000 ).limit( 100 );

skip

signature skip(number count)

returns SparkMongoCursor

Discards a given number of elements at the beginning of the cursor.

params

count - the limit to set

example

var cursor = collection.find( query ).skip( 1000 ).limit( 100 );

size

signature size()

returns number

Counts the number of objects matching the query this does take limit/skip into consideration.

example

var size = collection.find( query ).size();

count

signature count()

returns number

Counts the number of objects matching the query this does take limit/skip into consideration.

example

var count = collection.find( query ).count();

sort

signature sort(JSON orderBy)

returns SparkMongoCursor

Sorts this cursor's elements. This method must be called before getting any object from the cursor.

example

var cursor = collection.find( query ).sort( {"field" : 1} ).limit( 100 )

hasNext

signature hasNext()

returns boolean

Checks if there is another object available.

example

var cursor = collection.find( query ); if( cursor.hasNext() ) {var obj = cursor.next();}

next

signature next()

returns JSON

Returns the object the cursor is at and moves the cursor ahead by one.

returns

a JSON object

example

var cursor = collection.find( query ); if( cursor.hasNext() ) {var obj = cursor.next();}

curr

signature curr()

returns JSON

Returns the element the cursor is at.

returns

a JSON object

example

var cursor = collection.find( query ); if( cursor.hasNext() ) {cursor.next(); var obj = cursor.curr();}
Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here