MongoFindIterable
Processes search interactions across MongoDB collections.
all
all() : java.util.List<Values>
Description
Returns all matching documents as a list.
How To Use
const docs = collection.find().all();
Return
( java.util.List )
The list of all documents found.
first
first() : Values
Description
Returns the first document found or null if no document is found.
How To Use
const doc = collection.find().first();
Return
( Values )
The first document found, or null.
forEach
forEach(consumer: java.util.function.Consumer<Values>) : MongoFindIterable
Description
Iterates over the results using a Java Consumer.
How To Use
collection.find().forEach((doc) => _out.println(doc.getString('name')));
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| consumer | java.util.function.Consumer | The consumer to be called for each document. |
Return
forEach(func: org.graalvm.polyglot.Value) : MongoFindIterable
Description
Iterates over the results using a GraalVM polyglot function.
How To Use
collection.find().forEach((doc) => _out.println(doc));
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| func | org.graalvm.polyglot.Value | The function to be called for each document. |
Return
hint
hint(hint: org.bson.conversions.Bson) : MongoFindIterable
Description
Provides an index hint to optimize the query.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| hint | org.bson.conversions.Bson | The index hint document. |
Return
limit
limit(limit: int) : MongoFindIterable
Description
Sets the maximum number of results returned by the query.
How To Use
const docs = collection.find().limit(10).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| limit | int | The maximum number of results. |
Return
max
max(max: org.bson.conversions.Bson) : MongoFindIterable
Description
Sets the exclusive upper bound for a specific index. A null value means no max is set.
How To Use
collection.createIndex(_mongo.indexes().compoundIndex(
_mongo.indexes().descending('price'),
_mongo.indexes().ascending('quantity')
));
const indexHint = _mongo.valToDoc(_val.map().set('price', 1)).append('quantity', -1);
const maxBound = _mongo.valToDoc(_val.map().set('price', 200)).append('quantity', 23);
const docs = collection.find().hint(indexHint).max(maxBound).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| max | org.bson.conversions.Bson | The max. |
Return
min
min(min: org.bson.conversions.Bson) : MongoFindIterable
Description
Sets the inclusive lower bound for a specific index. A null value means no min is set.
How To Use
collection.createIndex(_mongo.indexes().compoundIndex(
_mongo.indexes().descending('price'),
_mongo.indexes().ascending('quantity')
));
const indexHint = _mongo.valToDoc(_val.map().set('price', 1)).append('quantity', -1);
const minBound = _mongo.valToDoc(_val.map().set('price', 50)).append('quantity', 10);
const docs = collection.find().hint(indexHint).min(minBound).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| min | org.bson.conversions.Bson | The min. |
Return
projection
projection(projection: org.bson.conversions.Bson) : MongoFindIterable
Description
Sets a document describing the fields to return for all matching documents.
How To Use
const docs = collection.find().projection(_mongo.projections().include('name', 'quantity')).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| projection | org.bson.conversions.Bson | The project document, which may be null. |
Return
skip
skip(skip: int) : MongoFindIterable
Description
Sets the number of results to skip before returning documents.
How To Use
const docs = collection.find().skip(5).limit(10).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| skip | int | The number of results to skip. |
Return
sort
sort(sort: org.bson.conversions.Bson) : MongoFindIterable
Description
Sets the sort order of the query results.
How To Use
const docs = collection.find().sort(_mongo.sorts().ascending('name')).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| sort | org.bson.conversions.Bson | The sort document. |