object Filters
A factory for query filters. A convenient way to use this class is to statically import all of its methods, which allows usage like:
collection.find(and(eq("x", 1), lt("y", 3)))
- Since
1.0
- Alphabetic
- By Inheritance
- Filters
- 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
- def all[TItem](fieldName: String, values: TItem*): Bson
Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
- TItem
the value type
- fieldName
the field name
- values
the list of values
- returns
the filter
- See also
- def and(filters: Bson*): Bson
Creates a filter that performs a logical AND of the provided list of filters.
Creates a filter that performs a logical AND of the provided list of filters. Note that this will only generate a "$and" operator if absolutely necessary, as the query language implicity ands together all the keys. In other words, a query expression like:
and(eq("x", 1), lt("y", 3))
will generate a MongoDB query like:
{x : 1, y : {$lt : 3}}
- filters
the list of filters to and together
- returns
the filter
- See also
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def bitsAllClear(fieldName: String, bitmask: Long): Bson
Creates a filter that matches all documents where all of the bit positions are clear in the field.
Creates a filter that matches all documents where all of the bit positions are clear in the field.
- fieldName
the field name
- bitmask
the bitmask
- returns
the filter
- Since
1.1
- Note
Requires MongoDB 3.2 or greater
- See also
- def bitsAllSet(fieldName: String, bitmask: Long): Bson
Creates a filter that matches all documents where all of the bit positions are set in the field.
Creates a filter that matches all documents where all of the bit positions are set in the field.
- fieldName
the field name
- bitmask
the bitmask
- returns
the filter
- Since
1.1
- Note
Requires MongoDB 3.2 or greater
- See also
- def bitsAnyClear(fieldName: String, bitmask: Long): Bson
Creates a filter that matches all documents where any of the bit positions are clear in the field.
Creates a filter that matches all documents where any of the bit positions are clear in the field.
- fieldName
the field name
- bitmask
the bitmask
- returns
the filter
- Since
1.1
- Note
Requires MongoDB 3.2 or greater
- See also
- def bitsAnySet(fieldName: String, bitmask: Long): Bson
Creates a filter that matches all documents where any of the bit positions are set in the field.
Creates a filter that matches all documents where any of the bit positions are set in the field.
- fieldName
the field name
- bitmask
the bitmask
- returns
the filter
- Since
1.1
- Note
Requires MongoDB 3.2 or greater
- See also
- def bsonType(fieldName: String, bsonType: BsonType): Bson
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
A friendly alias for the
type
method.- fieldName
the field name
- bsonType
the BSON type
- returns
the filter
- See also
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def elemMatch(fieldName: String, filter: Bson): Bson
Creates a filter that matches all documents containing a field that is an array where at least one member of the array matches the given filter.
Creates a filter that matches all documents containing a field that is an array where at least one member of the array matches the given filter.
- fieldName
the field name
- filter
the filter to apply to each element
- returns
the filter
- See also
- def empty(): Bson
Creates an empty filter that will match all documents.
Creates an empty filter that will match all documents.
- returns
the filter
- Since
4.2
- def eq[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the field name equals the specified value.
Creates a filter that matches all documents where the value of the field name equals the specified value. Note that this doesn't actually generate a
$eq
operator, as the query language doesn't require it.- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equal[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the field name equals the specified value.
Creates a filter that matches all documents where the value of the field name equals the specified value. Note that this does actually generate a
$eq
operator, as the query language doesn't require it.A friendly alias for the
eq
method.- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exists(fieldName: String, exists: Boolean): Bson
Creates a filter that matches all documents that either contain or do not contain the given field, depending on the value of the exists parameter.
Creates a filter that matches all documents that either contain or do not contain the given field, depending on the value of the exists parameter.
- fieldName
the field name
- exists
true to check for existence, false to check for absence
- returns
the filter
- See also
- def exists(fieldName: String): Bson
Creates a filter that matches all documents that contain the given field.
Creates a filter that matches all documents that contain the given field.
- fieldName
the field name
- returns
the filter
- See also
- def expr[TExpression](expression: TExpression): Bson
Allows the use of aggregation expressions within the query language.
Allows the use of aggregation expressions within the query language.
- TExpression
the expression type
- expression
the aggregation expression
- returns
the filter
- Since
2.2
- Note
Requires MongoDB 3.6 or greater
- def geoIntersects(fieldName: String, geometry: Geometry): Bson
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def geoIntersects(fieldName: String, geometry: Bson): Bson
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def geoWithin(fieldName: String, geometry: Bson): Bson
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def geoWithin(fieldName: String, geometry: Geometry): Bson
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def geoWithinBox(fieldName: String, lowerLeftX: Double, lowerLeftY: Double, upperRightX: Double, upperRightY: Double): Bson
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified box.
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified box.
- fieldName
the field name
- lowerLeftX
the lower left x coordinate of the box
- lowerLeftY
the lower left y coordinate of the box
- upperRightX
the upper left x coordinate of the box
- upperRightY
the upper left y coordinate of the box
- returns
the filter
- See also
- def geoWithinCenter(fieldName: String, x: Double, y: Double, radius: Double): Bson
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified circle.
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified circle.
- fieldName
the field name
- x
the x coordinate of the circle
- y
the y coordinate of the circle
- radius
the radius of the circle, as measured in the units used by the coordinate system
- returns
the filter
- See also
- def geoWithinCenterSphere(fieldName: String, x: Double, y: Double, radius: Double): Bson
Creates a filter that matches all documents containing a field with geospatial data (GeoJSON or legacy coordinate pairs) that exist entirely within the specified circle, using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data (GeoJSON or legacy coordinate pairs) that exist entirely within the specified circle, using spherical geometry. If using longitude and latitude, specify longitude first.
- fieldName
the field name
- x
the x coordinate of the circle
- y
the y coordinate of the circle
- radius
the radius of the circle, in radians
- returns
the filter
- See also
- def geoWithinPolygon(fieldName: String, points: Seq[Seq[Double]]): Bson
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified polygon.
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified polygon.
- fieldName
the field name
- points
a Seq of pairs of x, y coordinates. Any extra dimensions are ignored
- returns
the filter
- See also
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def gt[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the given field is greater than the specified value.
Creates a filter that matches all documents where the value of the given field is greater than the specified value.
- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- def gte[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value.
Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value.
- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def in[TItem](fieldName: String, values: TItem*): Bson
Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
- TItem
the value type
- fieldName
the field name
- values
the list of values
- returns
the filter
- See also
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def jsonSchema(schema: Bson): Bson
Creates a filter that matches all documents that validate against the given JSON schema document.
Creates a filter that matches all documents that validate against the given JSON schema document.
- schema
the JSON schema to validate against
- returns
the filter
- Since
2.2
- Note
Requires MongoDB 3.6 or greater
- def lt[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the given field is less than the specified value.
Creates a filter that matches all documents where the value of the given field is less than the specified value.
- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- def lte[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value.
Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value.
- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- def mod(fieldName: String, divisor: Long, remainder: Long): Bson
Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder (i.e.
Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder (i.e. perform a modulo operation to select documents).
- fieldName
the field name
- divisor
the modulus
- remainder
the remainder
- returns
the filter
- See also
- def ne[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the field name does not equal the specified value.
Creates a filter that matches all documents where the value of the field name does not equal the specified value.
- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def near(fieldName: String, x: Double, y: Double, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point.
- fieldName
the field name
- x
the x coordinate
- y
the y coordinate
- maxDistance
the optional maximum distance from the point, in radians
- minDistance
the optional minimum distance from the point, in radians
- returns
the filter
- See also
- def near(fieldName: String, x: Double, y: Double): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point.
- fieldName
the field name
- x
the x coordinate
- y
the y coordinate
- returns
the filter
- See also
- def near(fieldName: String, geometry: Bson, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- maxDistance
the optional maximum distance from the point, in meters
- minDistance
the optional minimum distance from the point, in meters
- returns
the filter
- See also
- def near(fieldName: String, geometry: Bson): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def near(fieldName: String, geometry: Point, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- maxDistance
the optional maximum distance from the point, in meters
- minDistance
the optional minimum distance from the point, in meters
- returns
the filter
- See also
- def near(fieldName: String, geometry: Point): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def nearSphere(fieldName: String, x: Double, y: Double, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point using spherical geometry.
- fieldName
the field name
- x
the x coordinate
- y
the y coordinate
- maxDistance
the optional maximum distance from the point, in radians
- minDistance
the optional minimum distance from the point, in radians
- returns
the filter
- See also
- def nearSphere(fieldName: String, x: Double, y: Double): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point using spherical geometry.
- fieldName
the field name
- x
the x coordinate
- y
the y coordinate
- returns
the filter
- See also
- def nearSphere(fieldName: String, geometry: Bson, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- maxDistance
the optional maximum distance from the point, in meters
- minDistance
the optional minimum distance from the point, in meters
- returns
the filter
- See also
- def nearSphere(fieldName: String, geometry: Bson): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def nearSphere(fieldName: String, geometry: Point, maxDistance: Option[Double], minDistance: Option[Double]): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- maxDistance
the optional maximum distance from the point, in meters
- minDistance
the optional minimum distance from the point, in meters
- returns
the filter
- See also
- def nearSphere(fieldName: String, geometry: Point): Bson
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using spherical geometry.
- fieldName
the field name
- geometry
the bounding GeoJSON geometry object
- returns
the filter
- See also
- def nin[TItem](fieldName: String, values: TItem*): Bson
Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist.
Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist.
- TItem
the value type
- fieldName
the field name
- values
the list of values
- returns
the filter
- See also
- def nor(filters: Bson*): Bson
Creates a filter that performs a logical NOR operation on all the specified filters.
Creates a filter that performs a logical NOR operation on all the specified filters.
- filters
the list of values
- returns
the filter
- See also
- def not(filter: Bson): Bson
Creates a filter that matches all documents that do not match the passed in filter.
Creates a filter that matches all documents that do not match the passed in filter. Requires the field name to passed as part of the value passed in and lifts it to create a valid "$not" query:
not(eq("x", 1))
will generate a MongoDB query like:
{x :$not: {$eq : 1}}
- filter
the value
- returns
the filter
- See also
- def notEqual[TItem](fieldName: String, value: TItem): Bson
Creates a filter that matches all documents where the value of the field name does not equal the specified value.
Creates a filter that matches all documents where the value of the field name does not equal the specified value.
A friendly alias for the
neq
method.- TItem
the value type
- fieldName
the field name
- value
the value
- returns
the filter
- See also
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def or(filters: Bson*): Bson
Creates a filter that preforms a logical OR of the provided list of filters.
Creates a filter that preforms a logical OR of the provided list of filters.
- filters
the list of filters to and together
- returns
the filter
- See also
- def regex(fieldName: String, regex: Regex): Bson
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern.
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern.
- fieldName
the field name
- regex
the regex
- returns
the filter
- Since
1.0
- See also
- def regex(fieldName: String, pattern: String, options: String): Bson
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
- fieldName
the field name
- pattern
the pattern
- options
the options
- returns
the filter
- See also
- def regex(fieldName: String, pattern: String): Bson
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern.
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern.
- fieldName
the field name
- pattern
the pattern
- returns
the filter
- See also
- def size(fieldName: String, size: Int): Bson
Creates a filter that matches all documents where the value of a field is an array of the specified size.
Creates a filter that matches all documents where the value of a field is an array of the specified size.
- fieldName
the field name
- size
the size of the array
- returns
the filter
- See also
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def text(search: String, textSearchOptions: TextSearchOptions): Bson
Creates a filter that matches all documents matching the given search term using the given language.
Creates a filter that matches all documents matching the given search term using the given language. You may use Projections.metaTextScore to extract the relevance score assigned to each matched document.
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
is a more powerful full-text search alternative.- search
the search term
- textSearchOptions
the text search options to use
- returns
the filter
- Since
1.1
- See also
- def text(search: String): Bson
Creates a filter that matches all documents matching the given search term.
Creates a filter that matches all documents matching the given search term. You may use Projections.metaTextScore to extract the relevance score assigned to each matched document.
Aggregates.search(SearchOperator, SearchOptions)
/Aggregates.search(SearchCollector, SearchOptions)
is a more powerful full-text search alternative.- search
the search term
- returns
the filter
- See also
- def toString(): String
- Definition Classes
- AnyRef → Any
- def type(fieldName: String, bsonType: BsonType): Bson
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
- fieldName
the field name
- bsonType
the BSON type
- returns
the filter
- See also
- 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])
- def where(javaScriptExpression: String): Bson
Creates a filter that matches all documents for which the given expression is true.
Creates a filter that matches all documents for which the given expression is true.
- javaScriptExpression
the JavaScript expression
- returns
the filter
- See also
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: