Class: Cursor

Longo. Cursor

Cursor object with command stack.
Cursor itself does not have, reference to result dataset.
All stacked command will never triggerd until receiver method will be called.
Asynchronously ,result dataset will be passed to receiver.

<private> new Cursor()

Do not call this class with new from application.

Source:
See:
  • Longo.Cursor.done
  • Longo.Cursor.onValue
  • Longo.Cursor.assign
  • Longo.Cursor.promise

Methods

<static> {Function} func javascript function() → {Cursor}

Iterates the cursor to apply a JavaScript function to each document from the cursor.
The func will be evaluate at Worker Thread. You should care for limitation of WebWorker.
If you want to work at Main-Thread, You can use simply use _.forEach to result set in done function.

Source:
Returns:

cursor Cursor object

Type
Cursor

<static> {Function} func javascript function() → {Cursor}

Applies function to each document visited by the cursor
and collects the return values from successive application into an array.
The func will be evaluate at Worker Thread. You should care for limitation of WebWorker.
If you want to work at Main-Thread, You can use simply use _.map to result set in done function.

Source:
Returns:

cursor Cursor object

Type
Cursor

assign(elementSelector, template) → {String}

Assign result set to dom element with template.
And observe collection change.

Parameters:
Name Type Description
elementSelector String

ElementSelector string or jQuery object Example: "p.myClass" , $("#myId")

template function

underscore.js template

Source:
Returns:

opId operation id

Type
String
Example
See live example for more detail.
var db = Longo.use("example");
var tpl = _.template($("#resultTpl").html());
db.collection("output").find({}).sort({"value":-1}).assign($("#out"), tpl);

count() → {Cursor}

Counts the number of documents referenced by a cursor.
Append the count() method to a Longo.Collection#find query to return the number of matching documents.
The operation does not perform the query but instead counts the results that would be returned by the query.
Diffeer from MongoShell, count does not take applySkipLimit parameter.
So this method is as same as Longo.Cursor#size

Source:
See:
Returns:

cursor Cursor object

Type
Cursor

done(cb) → {String}

Handle result set of query with Node.js callback style receiver

Parameters:
Name Type Description
cb cursorCallback

callback for result. See Longo.Cursor.cursorCallback

Source:
Returns:

opId operation id

Type
String

limit(num) → {Cursor}

Use the limit() method on a cursor to specify the maximum number of documents the cursor will return.

Parameters:
Name Type Description
num Number

limit

Source:
Returns:

cursor Cursor object

Type
Cursor

max(indexBounds) → {Cursor}

Specifies the exclusive upper bound for a specific field in order to constrain the results of Longo.Collection#find().
max() provides a way to specify an upper bound on compound field.

Parameters:
Name Type Description
indexBounds Object

The exclusive upper bound for the field

Source:
See:
Returns:

cursor Cursor object

Type
Cursor

min(indexBounds) → {Cursor}

Specifies the inclusive lower bound for a specific field in order to constrain the results of Longo.Collection#find().
min() provides a way to specify lower bounds on compound field.

Parameters:
Name Type Description
indexBounds Object

The exclusive lower bound for the field

Source:
See:
Returns:

cursor Cursor object

Type
Cursor

onValue(cb, skipDuplicates) → {String}

Handle result set of query with Node.js callback style receiver
And observe collection with same query, callback will be executed when collection changed.

Parameters:
Name Type Argument Default Description
cb cursorCallback

callback for result. See Longo.Cursor.cursorCallback

skipDuplicates Boolean <optional>
false

skipDuplicate Set true if you do not want to receive duplicate resultset.

Source:
Returns:

opId operation id

Type
String

promise() → {Promise}

Return Promise object for query.
You can access result with then or error with catch method.
This method does not return opId.

Source:
Returns:

promise object

Type
Promise

size() → {Cursor}

A count of the number of documents that match the Longo.Collection#find() query
after applying any cursor.skip() and cursor.limit() methods.

Source:
See:
Returns:

cursor Cursor object

Type
Cursor

skip(num) → {Cursor}

Call the cursor.skip() method on a cursor to control where MongoDB begins returning results.
This approach may be useful in implementing paged results.

Parameters:
Name Type Description
num Number

the number to skip

Source:
Returns:

cursor Cursor object

Type
Cursor

sort(sorter) → {Cursor}

Specifies the order in which the query returns matching documents. You must apply sort(). You can use sorter in two style.
1.field and value pairs: in this style, value must be 1 or -1 2.function: the function which will be applyed to result set as _.sort(dataset, sorter)

Parameters:
Name Type Description
sorter Object | function

see avobe

Source:
Returns:

cursor Cursor object

Type
Cursor

Type Definitions

cursorCallback(error, result)

Callback structure for Longo.Cursor

Parameters:
Name Type Argument Default Description
error Longo.Error <optional>
null

null when success

result Array <optional>
null

null when fail

Source: