<private> new Cursor()
Do not call this class with new
from application.
Methods
-
<static> {Function} func javascript function() → {Cursor}
-
Iterates the cursor to apply a JavaScript function to each document from the cursor.
Thefunc
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 indone
function.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.
Thefunc
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 indone
function.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
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 aLongo.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 takeapplySkipLimit
parameter.
So this method is as same asLongo.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
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
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.
Returns:
opId operation id
- Type
- String
-
promise() → {Promise}
-
Return
Promise
object for query.
You can access result withthen
or error withcatch
method.
This method does not return opId.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 implementingpaged
results.Parameters:
Name Type Description num
Number the number to skip
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 be1
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
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