Package com.mongodb.client.model
Class Aggregates
java.lang.Object
com.mongodb.client.model.Aggregates
Builders for aggregation pipeline stages.
- Since:
- 3.1
- MongoDB documentation
- Aggregation pipeline
- Since server release
- 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.bson.conversions.Bson
Creates an $addFields pipeline stagestatic org.bson.conversions.Bson
Creates an $addFields pipeline stagestatic <TExpression,
Boundary>
org.bson.conversions.BsonCreates a $bucket pipeline stagestatic <TExpression,
TBoundary>
org.bson.conversions.Bsonbucket
(TExpression groupBy, List<TBoundary> boundaries, BucketOptions options) Creates a $bucket pipeline stagestatic <TExpression>
org.bson.conversions.BsonbucketAuto
(TExpression groupBy, int buckets) Creates a $bucketAuto pipeline stagestatic <TExpression>
org.bson.conversions.BsonbucketAuto
(TExpression groupBy, int buckets, BucketAutoOptions options) Creates a $bucketAuto pipeline stagestatic org.bson.conversions.Bson
count()
Creates a $count pipeline stage using the field name "count" to store the resultstatic org.bson.conversions.Bson
Creates a $count pipeline stage using the named field to store the resultstatic org.bson.conversions.Bson
densify
(String field, DensifyRange range) Creates a$densify
pipeline stage, which adds documents to a sequence of documents where certain values in thefield
are missing.static org.bson.conversions.Bson
densify
(String field, DensifyRange range, DensifyOptions options) Creates a$densify
pipeline stage, which adds documents to a sequence of documents where certain values in thefield
are missing.static org.bson.conversions.Bson
Creates a $documents pipeline stage.static org.bson.conversions.Bson
Creates a facet pipeline stagestatic org.bson.conversions.Bson
Creates a facet pipeline stagestatic org.bson.conversions.Bson
fill
(FillOptions options, FillOutputField output, FillOutputField... moreOutput) Creates a$fill
pipeline stage, which assigns values to fields when they areNull
or missing.static org.bson.conversions.Bson
fill
(FillOptions options, Iterable<? extends FillOutputField> output) Creates a$fill
pipeline stage, which assigns values to fields when they areNull
or missing.static org.bson.conversions.Bson
Creates a $geoNear pipeline stage that outputs documents in order of nearest to farthest from a specified point.static org.bson.conversions.Bson
geoNear
(Point near, String distanceField, GeoNearOptions options) Creates a $geoNear pipeline stage that outputs documents in order of nearest to farthest from a specified point.static <TExpression>
org.bson.conversions.BsongraphLookup
(String from, TExpression startWith, String connectFromField, String connectToField, String as) Creates a graphLookup pipeline stage for the specified filterstatic <TExpression>
org.bson.conversions.BsongraphLookup
(String from, TExpression startWith, String connectFromField, String connectToField, String as, GraphLookupOptions options) Creates a graphLookup pipeline stage for the specified filterstatic <TExpression>
org.bson.conversions.BsonCreates a $group pipeline stage for the specified filterstatic <TExpression>
org.bson.conversions.BsonCreates a $group pipeline stage for the specified filterstatic org.bson.conversions.Bson
limit
(int limit) Creates a $limit pipeline stage for the specified filterstatic org.bson.conversions.Bson
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign fieldstatic org.bson.conversions.Bson
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline.static <TExpression>
org.bson.conversions.Bsonlookup
(String from, List<Variable<TExpression>> let, List<? extends org.bson.conversions.Bson> pipeline, String as) Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline.static org.bson.conversions.Bson
match
(org.bson.conversions.Bson filter) Creates a $match pipeline stage for the specified filterstatic org.bson.conversions.Bson
merge
(MongoNamespace namespace) Creates a $merge pipeline stage that merges into the specified namespacestatic org.bson.conversions.Bson
merge
(MongoNamespace namespace, MergeOptions options) Creates a $merge pipeline stage that merges into the specified namespace using the specified options.static org.bson.conversions.Bson
Creates a $merge pipeline stage that merges into the specified collectionstatic org.bson.conversions.Bson
merge
(String collectionName, MergeOptions options) Creates a $merge pipeline stage that merges into the specified collection using the specified options.static org.bson.conversions.Bson
Creates a $out pipeline stage that writes into the specified collectionstatic org.bson.conversions.Bson
Creates a $out pipeline stage that supports outputting to a different database.static org.bson.conversions.Bson
out
(org.bson.conversions.Bson destination) Creates a $out pipeline stage that writes out to the specified destinationstatic org.bson.conversions.Bson
project
(org.bson.conversions.Bson projection) Creates a $project pipeline stage for the specified projectionstatic <TExpression>
org.bson.conversions.BsonreplaceRoot
(TExpression value) Creates a $replaceRoot pipeline stagestatic <TExpression>
org.bson.conversions.BsonreplaceWith
(TExpression value) Creates a $replaceRoot pipeline stagestatic org.bson.conversions.Bson
sample
(int size) Creates a $sample pipeline stage with the specified sample sizestatic org.bson.conversions.Bson
search
(SearchCollector collector) Creates a$search
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
search
(SearchCollector collector, SearchOptions options) Creates a$search
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
search
(SearchOperator operator) Creates a$search
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
search
(SearchOperator operator, SearchOptions options) Creates a$search
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
searchMeta
(SearchCollector collector) Creates a$searchMeta
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
searchMeta
(SearchCollector collector, SearchOptions options) Creates a$searchMeta
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
searchMeta
(SearchOperator operator) Creates a$searchMeta
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
searchMeta
(SearchOperator operator, SearchOptions options) Creates a$searchMeta
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
Creates a $set pipeline stage for the specified projectionstatic org.bson.conversions.Bson
Creates a $set pipeline stage for the specified projectionstatic <TExpression>
org.bson.conversions.BsonsetWindowFields
(TExpression partitionBy, org.bson.conversions.Bson sortBy, WindowOutputField output, WindowOutputField... moreOutput) Creates a$setWindowFields
pipeline stage, which allows using window operators.static <TExpression>
org.bson.conversions.BsonsetWindowFields
(TExpression partitionBy, org.bson.conversions.Bson sortBy, Iterable<? extends WindowOutputField> output) Creates a$setWindowFields
pipeline stage, which allows using window operators.static org.bson.conversions.Bson
skip
(int skip) Creates a $skip pipeline stagestatic org.bson.conversions.Bson
sort
(org.bson.conversions.Bson sort) Creates a $sort pipeline stage for the specified sort specificationstatic <TExpression>
org.bson.conversions.BsonsortByCount
(TExpression filter) Creates a $sortByCount pipeline stage for the specified filterstatic org.bson.conversions.Bson
Creates a $unionWith pipeline stage.static org.bson.conversions.Bson
Creates an $unset pipeline stage that removes/excludes fields from documentsstatic org.bson.conversions.Bson
Creates an $unset pipeline stage that removes/excludes fields from documentsstatic org.bson.conversions.Bson
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.static org.bson.conversions.Bson
unwind
(String fieldName, UnwindOptions unwindOptions) Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.static org.bson.conversions.Bson
vectorSearch
(FieldSearchPath path, Iterable<Double> queryVector, String index, long limit, VectorSearchOptions options) Creates a$vectorSearch
pipeline stage supported by MongoDB Atlas.static org.bson.conversions.Bson
vectorSearch
(FieldSearchPath path, org.bson.BinaryVector queryVector, String index, long limit, VectorSearchOptions options) Creates a$vectorSearch
pipeline stage supported by MongoDB Atlas.
-
Method Details
-
addFields
Creates an $addFields pipeline stage- Parameters:
fields
- the fields to add- Returns:
- the $addFields pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $addFields
- Since server release
- 3.4
-
addFields
Creates an $addFields pipeline stage- Parameters:
fields
- the fields to add- Returns:
- the $addFields pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $addFields
- Since server release
- 3.4
-
set
Creates a $set pipeline stage for the specified projection- Parameters:
fields
- the fields to add- Returns:
- the $set pipeline stage
- Since:
- 4.3
- See Also:
-
set
Creates a $set pipeline stage for the specified projection- Parameters:
fields
- the fields to add- Returns:
- the $set pipeline stage
- Since:
- 4.3
- See Also:
-
bucket
public static <TExpression,Boundary> org.bson.conversions.Bson bucket(TExpression groupBy, List<Boundary> boundaries) Creates a $bucket pipeline stage -
bucket
public static <TExpression,TBoundary> org.bson.conversions.Bson bucket(TExpression groupBy, List<TBoundary> boundaries, BucketOptions options) Creates a $bucket pipeline stage- Type Parameters:
TExpression
- the groupBy expression typeTBoundary
- the boundary type- Parameters:
groupBy
- the criteria to group Byboundaries
- the boundaries of the bucketsoptions
- the optional values for the $bucket stage- Returns:
- the $bucket pipeline stage
- Since:
- 3.4
-
bucketAuto
public static <TExpression> org.bson.conversions.Bson bucketAuto(TExpression groupBy, int buckets) Creates a $bucketAuto pipeline stage- Type Parameters:
TExpression
- the groupBy expression type- Parameters:
groupBy
- the criteria to group Bybuckets
- the number of the buckets- Returns:
- the $bucketAuto pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $bucketAuto
- Since server release
- 3.4
-
bucketAuto
public static <TExpression> org.bson.conversions.Bson bucketAuto(TExpression groupBy, int buckets, BucketAutoOptions options) Creates a $bucketAuto pipeline stage- Type Parameters:
TExpression
- the groupBy expression type- Parameters:
groupBy
- the criteria to group Bybuckets
- the number of the bucketsoptions
- the optional values for the $bucketAuto stage- Returns:
- the $bucketAuto pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $bucketAuto
- Since server release
- 3.4
-
count
public static org.bson.conversions.Bson count()Creates a $count pipeline stage using the field name "count" to store the result -
count
Creates a $count pipeline stage using the named field to store the result -
match
public static org.bson.conversions.Bson match(org.bson.conversions.Bson filter) Creates a $match pipeline stage for the specified filter -
project
public static org.bson.conversions.Bson project(org.bson.conversions.Bson projection) Creates a $project pipeline stage for the specified projection- Parameters:
projection
- the projection- Returns:
- the $project pipeline stage
- See Also:
- MongoDB documentation
- $project
-
sort
public static org.bson.conversions.Bson sort(org.bson.conversions.Bson sort) Creates a $sort pipeline stage for the specified sort specification -
sortByCount
public static <TExpression> org.bson.conversions.Bson sortByCount(TExpression filter) Creates a $sortByCount pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
filter
- the filter specification- Returns:
- the $sortByCount pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $sortByCount
- Since server release
- 3.4
-
skip
public static org.bson.conversions.Bson skip(int skip) Creates a $skip pipeline stage- Parameters:
skip
- the number of documents to skip- Returns:
- the $skip pipeline stage
- MongoDB documentation
- $skip
-
limit
public static org.bson.conversions.Bson limit(int limit) Creates a $limit pipeline stage for the specified filter- Parameters:
limit
- the limit- Returns:
- the $limit pipeline stage
- MongoDB documentation
- $limit
-
lookup
public static org.bson.conversions.Bson lookup(String from, String localField, String foreignField, String as) Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign field- Parameters:
from
- the name of the collection in the same database to perform the join with.localField
- the field from the local collection to match values against.foreignField
- the field in the from collection to match values against.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.2
-
lookup
public static org.bson.conversions.Bson lookup(@Nullable String from, List<? extends org.bson.conversions.Bson> pipeline, String as) Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline. If the first stage in the pipeline is a$documents
stage, then thefrom
collection is ignored.- Parameters:
from
- the name of the collection in the same database to perform the join with. Must be {$code null} if the first pipeline stage is $documents.pipeline
- the pipeline to run on the joined collection.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.7
-
lookup
public static <TExpression> org.bson.conversions.Bson lookup(@Nullable String from, @Nullable List<Variable<TExpression>> let, List<? extends org.bson.conversions.Bson> pipeline, String as) Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline. If the first stage in the pipeline is a$documents
stage, then thefrom
collection is ignored.- Type Parameters:
TExpression
- the Variable value expression type- Parameters:
from
- the name of the collection in the same database to perform the join with. Must be {$code null} if the first pipeline stage is $documents.let
- the variables to use in the pipeline field stages.pipeline
- the pipeline to run on the joined collection.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.7
-
facet
Creates a facet pipeline stage -
facet
Creates a facet pipeline stage -
graphLookup
public static <TExpression> org.bson.conversions.Bson graphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as) Creates a graphLookup pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
from
- the collection to querystartWith
- the expression to start the graph lookup withconnectFromField
- the from fieldconnectToField
- the to fieldas
- name of field in output document- Returns:
- the $graphLookup pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $graphLookup
- Since server release
- 3.4
-
graphLookup
public static <TExpression> org.bson.conversions.Bson graphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as, GraphLookupOptions options) Creates a graphLookup pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
from
- the collection to querystartWith
- the expression to start the graph lookup withconnectFromField
- the from fieldconnectToField
- the to fieldas
- name of field in output documentoptions
- optional values for the graphLookup- Returns:
- the $graphLookup pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $graphLookup
- Since server release
- 3.4
-
group
public static <TExpression> org.bson.conversions.Bson group(@Nullable TExpression id, BsonField... fieldAccumulators) Creates a $group pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
id
- the id expression for the group, which may be nullfieldAccumulators
- zero or more field accumulator pairs- Returns:
- the $group pipeline stage
- MongoDB documentation
- $group
- Expressions
-
group
public static <TExpression> org.bson.conversions.Bson group(@Nullable TExpression id, List<BsonField> fieldAccumulators) Creates a $group pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
id
- the id expression for the group, which may be nullfieldAccumulators
- zero or more field accumulator pairs- Returns:
- the $group pipeline stage
- MongoDB documentation
- $group
- Expressions
-
unionWith
public static org.bson.conversions.Bson unionWith(String collection, List<? extends org.bson.conversions.Bson> pipeline) Creates a $unionWith pipeline stage.- Parameters:
collection
- the name of the collection in the same database to perform the union with.pipeline
- the pipeline to run on the union.- Returns:
- the $unionWith pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $unionWith
- Since server release
- 4.4
-
unwind
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.- Parameters:
fieldName
- the field name, prefixed by a'$' sign
- Returns:
- the $unwind pipeline stage
- MongoDB documentation
- $unwind
-
unwind
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign. -
out
Creates a $out pipeline stage that writes into the specified collection- Parameters:
collectionName
- the collection name- Returns:
- the $out pipeline stage
- MongoDB documentation
- $out
-
out
Creates a $out pipeline stage that supports outputting to a different database. -
out
public static org.bson.conversions.Bson out(org.bson.conversions.Bson destination) Creates a $out pipeline stage that writes out to the specified destination- Parameters:
destination
- the destination details- Returns:
- the $out pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $out
-
merge
Creates a $merge pipeline stage that merges into the specified collection -
merge
Creates a $merge pipeline stage that merges into the specified namespace -
merge
Creates a $merge pipeline stage that merges into the specified collection using the specified options. -
merge
Creates a $merge pipeline stage that merges into the specified namespace using the specified options. -
replaceRoot
public static <TExpression> org.bson.conversions.Bson replaceRoot(TExpression value) Creates a $replaceRoot pipeline stage- Type Parameters:
TExpression
- the new root type- Parameters:
value
- the new root value- Returns:
- the $replaceRoot pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $replaceRoot
- Since server release
- 3.4
-
replaceWith
public static <TExpression> org.bson.conversions.Bson replaceWith(TExpression value) Creates a $replaceRoot pipeline stageWith $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.
The $replaceWith is an alias for
replaceRoot(Object)
.- Type Parameters:
TExpression
- the new root type- Parameters:
value
- the new root value- Returns:
- the $replaceRoot pipeline stage
- Since:
- 3.11
- MongoDB documentation
- $replaceWith
- Since server release
- 4.2
-
sample
public static org.bson.conversions.Bson sample(int size) Creates a $sample pipeline stage with the specified sample size -
setWindowFields
public static <TExpression> org.bson.conversions.Bson setWindowFields(@Nullable TExpression partitionBy, @Nullable org.bson.conversions.Bson sortBy, WindowOutputField output, WindowOutputField... moreOutput) Creates a$setWindowFields
pipeline stage, which allows using window operators. This stage partitions the input documents similarly to the$group
pipeline stage, optionally sorts them, computes fields in the documents by computing window functions over windows specified per function, and outputs the documents. The important difference from the$group
pipeline stage is that documents belonging to the same partition or window are not folded into a single document.- Type Parameters:
TExpression
- ThepartitionBy
expression type.- Parameters:
partitionBy
- Optional partitioning of data specified likeid
ingroup(Object, List)
. Ifnull
, then all documents belong to the same partition.sortBy
- Fields to sort by. The syntax is identical tosort
insort(Bson)
(seeSorts
). Sorting is required by certain functions and may be required by some windows (seeWindows
for more details). Sorting is used only for the purpose of computing window functions and does not guarantee ordering of the output documents.output
- A windowed computation.moreOutput
- More windowed computations.- Returns:
- The
$setWindowFields
pipeline stage. - Since:
- 4.3
- MongoDB documentation
- $setWindowFields
- Since server release
- 5.0
-
setWindowFields
public static <TExpression> org.bson.conversions.Bson setWindowFields(@Nullable TExpression partitionBy, @Nullable org.bson.conversions.Bson sortBy, Iterable<? extends WindowOutputField> output) Creates a$setWindowFields
pipeline stage, which allows using window operators. This stage partitions the input documents similarly to the$group
pipeline stage, optionally sorts them, computes fields in the documents by computing window functions over windows specified per function, and outputs the documents. The important difference from the$group
pipeline stage is that documents belonging to the same partition or window are not folded into a single document.- Type Parameters:
TExpression
- ThepartitionBy
expression type.- Parameters:
partitionBy
- Optional partitioning of data specified likeid
ingroup(Object, List)
. Ifnull
, then all documents belong to the same partition.sortBy
- Fields to sort by. The syntax is identical tosort
insort(Bson)
(seeSorts
). Sorting is required by certain functions and may be required by some windows (seeWindows
for more details). Sorting is used only for the purpose of computing window functions and does not guarantee ordering of the output documents.output
- A list of windowed computations. Specifying an empty list is not an error, but the resulting stage does not do anything useful.- Returns:
- The
$setWindowFields
pipeline stage. - Since:
- 4.3
- MongoDB documentation
- $setWindowFields
- Since server release
- 5.0
-
densify
Creates a$densify
pipeline stage, which adds documents to a sequence of documents where certain values in thefield
are missing.- Parameters:
field
- The field to densify.range
- The range.- Returns:
- The requested pipeline stage.
- Since:
- 4.7
- MongoDB documentation
- $densify
- Dot notation
- Since server release
- 5.1
-
densify
public static org.bson.conversions.Bson densify(String field, DensifyRange range, DensifyOptions options) Creates a$densify
pipeline stage, which adds documents to a sequence of documents where certain values in thefield
are missing.- Parameters:
field
- The field to densify.range
- The range.options
- The densify options. SpecifyingDensifyOptions.densifyOptions()
is equivalent to callingdensify(String, DensifyRange)
.- Returns:
- The requested pipeline stage.
- Since:
- 4.7
- MongoDB documentation
- $densify
- Dot notation
- Since server release
- 5.1
-
fill
public static org.bson.conversions.Bson fill(FillOptions options, FillOutputField output, FillOutputField... moreOutput) Creates a$fill
pipeline stage, which assigns values to fields when they areNull
or missing.- Parameters:
options
- The fill options.output
- TheFillOutputField
.moreOutput
- MoreFillOutputField
s.- Returns:
- The requested pipeline stage.
- Since:
- 4.7
-
fill
public static org.bson.conversions.Bson fill(FillOptions options, Iterable<? extends FillOutputField> output) Creates a$fill
pipeline stage, which assigns values to fields when they areNull
or missing.- Parameters:
options
- The fill options.output
- The non-emptyFillOutputField
s.- Returns:
- The requested pipeline stage.
- Since:
- 4.7
-
search
Creates a$search
pipeline stage supported by MongoDB Atlas. You may use the$meta: "searchScore"
expression, e.g., viaProjections.metaSearchScore(String)
, to extract the relevance score assigned to each found document.Filters.text(String, TextSearchOptions)
is a legacy text search alternative.- Parameters:
operator
- A search operator.- Returns:
- The
$search
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $search
- Search operators
- Scoring
-
search
Creates a$search
pipeline stage supported by MongoDB Atlas. You may use the$meta: "searchScore"
expression, e.g., viaProjections.metaSearchScore(String)
, to extract the relevance score assigned to each found document.Filters.text(String, TextSearchOptions)
is a legacy text search alternative.- Parameters:
operator
- A search operator.options
- Optional$search
pipeline stage fields. SpecifyingSearchOptions.searchOptions()
is equivalent to callingsearch(SearchOperator)
.- Returns:
- The
$search
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $search
- Search operators
- Scoring
-
search
Creates a$search
pipeline stage supported by MongoDB Atlas. You may use$meta: "searchScore"
, e.g., viaProjections.metaSearchScore(String)
, to extract the relevance score assigned to each found document.- Parameters:
collector
- A search collector.- Returns:
- The
$search
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $search
- Search collectors
- Scoring
-
search
Creates a$search
pipeline stage supported by MongoDB Atlas. You may use$meta: "searchScore"
, e.g., viaProjections.metaSearchScore(String)
, to extract the relevance score assigned to each found document.- Parameters:
collector
- A search collector.options
- Optional$search
pipeline stage fields. SpecifyingSearchOptions.searchOptions()
is equivalent to callingsearch(SearchCollector)
.- Returns:
- The
$search
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $search
- Search collectors
- Scoring
-
searchMeta
Creates a$searchMeta
pipeline stage supported by MongoDB Atlas. Unlike$search
, it does not return found documents, instead it returns metadata, which in case of using the$search
stage may be extracted by using$$SEARCH_META
variable, e.g., viaProjections.computedSearchMeta(String)
.- Parameters:
operator
- A search operator.- Returns:
- The
$searchMeta
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $searchMeta
- Search operators
-
searchMeta
Creates a$searchMeta
pipeline stage supported by MongoDB Atlas. Unlike$search
, it does not return found documents, instead it returns metadata, which in case of using the$search
stage may be extracted by using$$SEARCH_META
variable, e.g., viaProjections.computedSearchMeta(String)
.- Parameters:
operator
- A search operator.options
- Optional$search
pipeline stage fields. SpecifyingSearchOptions.searchOptions()
is equivalent to callingsearchMeta(SearchOperator)
.- Returns:
- The
$searchMeta
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $searchMeta
- Search operators
-
searchMeta
Creates a$searchMeta
pipeline stage supported by MongoDB Atlas. Unlike$search
, it does not return found documents, instead it returns metadata, which in case of using the$search
stage may be extracted by using$$SEARCH_META
variable, e.g., viaProjections.computedSearchMeta(String)
.- Parameters:
collector
- A search collector.- Returns:
- The
$searchMeta
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $searchMeta
- Search collectors
-
searchMeta
public static org.bson.conversions.Bson searchMeta(SearchCollector collector, SearchOptions options) Creates a$searchMeta
pipeline stage supported by MongoDB Atlas. Unlike$search
, it does not return found documents, instead it returns metadata, which in case of using the$search
stage may be extracted by using$$SEARCH_META
variable, e.g., viaProjections.computedSearchMeta(String)
.- Parameters:
collector
- A search collector.options
- Optional$search
pipeline stage fields. SpecifyingSearchOptions.searchOptions()
is equivalent to callingsearchMeta(SearchCollector)
.- Returns:
- The
$searchMeta
pipeline stage. - Since:
- 4.7
- MongoDB Atlas documentation
- $searchMeta
- Search collectors
-
vectorSearch
public static org.bson.conversions.Bson vectorSearch(FieldSearchPath path, Iterable<Double> queryVector, String index, long limit, VectorSearchOptions options) Creates a$vectorSearch
pipeline stage supported by MongoDB Atlas. You may use the$meta: "vectorSearchScore"
expression, e.g., viaProjections.metaVectorSearchScore(String)
, to extract the relevance score assigned to each found document.- Parameters:
queryVector
- The query vector. The number of dimensions must match that of theindex
.path
- The field to be searched.index
- The name of the index to use.limit
- The limit on the number of documents produced by the pipeline stage.options
- Optional$vectorSearch
pipeline stage fields.- Returns:
- The
$vectorSearch
pipeline stage. - Since:
- 4.11
- MongoDB Atlas documentation
- $vectorSearch
- Scoring
- Since server release
- 6.0.11
-
vectorSearch
public static org.bson.conversions.Bson vectorSearch(FieldSearchPath path, org.bson.BinaryVector queryVector, String index, long limit, VectorSearchOptions options) Creates a$vectorSearch
pipeline stage supported by MongoDB Atlas. You may use the$meta: "vectorSearchScore"
expression, e.g., viaProjections.metaVectorSearchScore(String)
, to extract the relevance score assigned to each found document.- Parameters:
queryVector
- The query vector. The number of dimensions must match that of theindex
.path
- The field to be searched.index
- The name of the index to use.limit
- The limit on the number of documents produced by the pipeline stage.options
- Optional$vectorSearch
pipeline stage fields.- Returns:
- The
$vectorSearch
pipeline stage. - Since:
- 5.3
- See Also:
-
BinaryVector
- MongoDB Atlas documentation
- $vectorSearch
- Scoring
- Since server release
- 6.0
-
unset
Creates an $unset pipeline stage that removes/excludes fields from documents -
unset
Creates an $unset pipeline stage that removes/excludes fields from documents -
geoNear
public static org.bson.conversions.Bson geoNear(Point near, String distanceField, GeoNearOptions options) Creates a $geoNear pipeline stage that outputs documents in order of nearest to farthest from a specified point.- Parameters:
near
- The point for which to find the closest documents.distanceField
- The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.options
-GeoNearOptions
- Returns:
- the $geoNear pipeline stage
- Since:
- 4.8
- MongoDB documentation
- $geoNear
-
geoNear
Creates a $geoNear pipeline stage that outputs documents in order of nearest to farthest from a specified point.- Parameters:
near
- The point for which to find the closest documents.distanceField
- The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.- Returns:
- the $geoNear pipeline stage
- Since:
- 4.8
- MongoDB documentation
- $geoNear
-
documents
public static org.bson.conversions.Bson documents(List<? extends org.bson.conversions.Bson> documents) Creates a $documents pipeline stage.- Parameters:
documents
- the documents.- Returns:
- the $documents pipeline stage.
- Since:
- 4.9
- MongoDB documentation
- $documents
- Since server release
- 5.1
-