object Projections
A factory for projections. A convenient way to use this class is to statically import all of its methods, which allows usage like:
collection.find().projection(fields(include("x", "y"), excludeId()))
- Since
1.0
- Alphabetic
- By Inheritance
- Projections
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def computed[TExpression](fieldName: String, expression: TExpression): Bson
Creates a projection of a field whose value is computed from the given expression.
Creates a projection of a field whose value is computed from the given expression. Projection with an expression can be used in the following contexts:
- $project aggregation pipeline stage.
- Starting from MongoDB 4.4, it's also accepted in various find-related methods within the
MongoCollection
-based API where projection is supported, for example: find()
findOneAndReplace()
findOneAndUpdate()
findOneAndDelete()
- TExpression
the expression type
- fieldName
the field name
- expression
the expression
- returns
the projection
- See also
Aggregates#project(Bson)
- def computedSearchMeta(fieldName: String): Bson
Creates a projection of a field whose value is equal to the
$$SEARCH_META
variable, for use withAggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
.Creates a projection of a field whose value is equal to the
$$SEARCH_META
variable, for use withAggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
. Calling this method is equivalent to calling Projections.computed with"$$SEARCH_META"
as the second argument.- fieldName
the field name
- returns
the projection
- def elemMatch(fieldName: String, filter: Bson): Bson
Creates a projection that includes for the given field only the first element of the array value of that field that matches the given query filter.
Creates a projection that includes for the given field only the first element of the array value of that field that matches the given query filter.
- fieldName
the field name
- filter
the filter to apply
- returns
the projection
- See also
- def elemMatch(fieldName: String): Bson
Creates a projection that includes for the given field only the first element of an array that matches the query filter.
Creates a projection that includes for the given field only the first element of an array that matches the query filter. This is referred to as the positional
$
operator.- fieldName
the field name whose value is the array
- returns
the projection
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exclude(fieldNames: String*): Bson
Creates a projection that excludes all of the given fields.
Creates a projection that excludes all of the given fields.
- fieldNames
the field names
- returns
the projection
- def excludeId(): Bson
Creates a projection that excludes the _id field.
Creates a projection that excludes the _id field. This suppresses the automatic inclusion of _id that is the default, even when other fields are explicitly included.
- returns
the projection
- def fields(projections: Bson*): Bson
Creates a projection that combines the list of projections into a single one.
Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.
- projections
the list of projections to combine
- returns
the combined projection
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def include(fieldNames: String*): Bson
Creates a projection that includes all of the given fields.
Creates a projection that includes all of the given fields.
- fieldNames
the field names
- returns
the projection
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def meta(fieldName: String, metaFieldName: String): Bson
Creates a
$meta
projection to the given field name for the given meta field name.Creates a
$meta
projection to the given field name for the given meta field name.- fieldName
the field name
- metaFieldName
the meta field name
- returns
the projection
- def metaSearchHighlights(fieldName: String): Bson
Creates a projection to the given field name of the searchHighlights, for use with
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
.Creates a projection to the given field name of the searchHighlights, for use with
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
. Calling this method is equivalent to calling Projections.meta with"searchHighlights"
as the second argument.- fieldName
the field name
- returns
the projection
- def metaSearchScore(fieldName: String): Bson
Creates a projection to the given field name of the searchScore, for use with
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
.Creates a projection to the given field name of the searchScore, for use with
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
. Calling this method is equivalent to calling Projections.meta with"searchScore"
as the second argument.- fieldName
the field name
- returns
the projection
- See also
- def metaTextScore(fieldName: String): Bson
Creates a projection to the given field name of the textScore, for use with text queries.
Creates a projection to the given field name of the textScore, for use with text queries. Calling this method is equivalent to calling Projections.meta with
"textScore"
as the second argument.- fieldName
the field name
- returns
the projection
- See also
Filters.text(String, TextSearchOptions)
- def metaVectorSearchScore(fieldName: String): Bson
Creates a projection to the given field name of the vectorSearchScore, for use with
Aggregates.vectorSearch(FieldSearchPath, Iterable, String, Long, Long, VectorSearchOptions)
.Creates a projection to the given field name of the vectorSearchScore, for use with
Aggregates.vectorSearch(FieldSearchPath, Iterable, String, Long, Long, VectorSearchOptions)
. Calling this method is equivalent to calling Projections.meta with"vectorSearchScore"
as the second argument.- fieldName
the field name
- returns
the projection
- Since
4.11
- Note
Requires MongoDB 6.0.10 or greater
- See also
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def slice(fieldName: String, skip: Int, limit: Int): Bson
Creates a projection to the given field name of a slice of the array value of that field.
Creates a projection to the given field name of a slice of the array value of that field.
- fieldName
the field name
- skip
the number of elements to skip before applying the limit
- limit
the number of elements to project
- returns
the projection
- See also
- def slice(fieldName: String, limit: Int): Bson
Creates a projection to the given field name of a slice of the array value of that field.
Creates a projection to the given field name of a slice of the array value of that field.
- fieldName
the field name
- limit
the number of elements to project.
- returns
the projection
- See also
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
This is the documentation for the MongoDB Scala driver.
Driver structure
The mongodb scala driver.
To get started you need a MongoClient instance, either from a connection string or via a org.mongodb.scala.MongoClientSettings.
Notable packages include: