Skip to main content

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
NAMETYPEDESCRIPTION
consumerjava.util.function.ConsumerThe consumer to be called for each document.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
funcorg.graalvm.polyglot.ValueThe function to be called for each document.
Return

( MongoFindIterable )


hint


hint(hint: org.bson.conversions.Bson) : MongoFindIterable

Description

Provides an index hint to optimize the query.

Attributes
NAMETYPEDESCRIPTION
hintorg.bson.conversions.BsonThe index hint document.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
limitintThe maximum number of results.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
maxorg.bson.conversions.BsonThe max.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
minorg.bson.conversions.BsonThe min.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
projectionorg.bson.conversions.BsonThe project document, which may be null.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
skipintThe number of results to skip.
Return

( MongoFindIterable )


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
NAMETYPEDESCRIPTION
sortorg.bson.conversions.BsonThe sort document.
Return

( MongoFindIterable )