Package com.mongodb.client.model.search
Interface SearchCollector
- All Superinterfaces:
Bson
- All Known Subinterfaces:
FacetSearchCollector
The core part of the
$search pipeline stage of an aggregation pipeline.
SearchCollectors allow returning metadata together with the search results.
You may use the $$SEARCH_META variable, e.g., via Projections.computedSearchMeta(String), to extract this metadata.- Since:
- 4.7
- MongoDB Atlas documentation
- Search collectors
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic FacetSearchCollectorfacet(SearchOperator operator, Iterable<? extends SearchFacet> facets) Returns aSearchCollectorthat groups the results of a search based on the specified operator by values or ranges in the specified faceted fields, and returns the count for each of those groups.static FacetSearchCollectorfacet(Iterable<? extends SearchFacet> facets) Returns aSearchCollectorthat groups all the input documents by values or ranges in the specified faceted fields, and returns the count for each of those groups.static SearchCollectorCreates aSearchCollectorfrom aBsonin situations when there is no builder method that better satisfies your needs.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
facet
Returns aSearchCollectorthat groups the results of a search based on the specified operator by values or ranges in the specified faceted fields, and returns the count for each of those groups.- Parameters:
operator- The search operator to use.facets- The non-empty facet definitions.- Returns:
- The requested
SearchCollector. - MongoDB Atlas documentation
- facet collector
-
facet
Returns aSearchCollectorthat groups all the input documents by values or ranges in the specified faceted fields, and returns the count for each of those groups.- Parameters:
facets- The non-empty facet definitions.- Returns:
- The requested
SearchCollector. - MongoDB Atlas documentation
- facet collector
-
of
Creates aSearchCollectorfrom aBsonin situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.Example
The following code creates two functionally equivalentSearchCollectors, though they may not be equal.SearchCollector collector1 = SearchCollector.facet( SearchOperator.exists( SearchPath.fieldPath("fieldName")), Arrays.asList( SearchFacet.stringFacet( "stringFacetName", SearchPath.fieldPath("stringFieldName")), SearchFacet.numberFacet( "numberFacetName", SearchPath.fieldPath("numberFieldName"), Arrays.asList(10, 20, 30)))); SearchCollector collector2 = SearchCollector.of(new Document("facet", new Document("operator", SearchOperator.exists( SearchPath.fieldPath("fieldName"))) .append("facets", SearchFacet.combineToBson(Arrays.asList( SearchFacet.stringFacet( "stringFacetName", SearchPath.fieldPath("stringFieldName")), SearchFacet.numberFacet( "numberFacetName", SearchPath.fieldPath("numberFieldName"), Arrays.asList(10, 20, 30)))))));- Parameters:
collector- ABsonrepresenting the requiredSearchCollector.- Returns:
- The requested
SearchCollector.
-