Class MongoFilters

java.lang.Object
services.moleculer.mongo.MongoFilters
Direct Known Subclasses:
MongoDAO

public class MongoFilters extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected io.datatree.Tree
    all(String fieldName, Object... values)
    Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
    protected io.datatree.Tree
    and(io.datatree.Tree... filters)
    Creates a filter that performs a logical AND of the provided list of filters.
    protected io.datatree.Tree
    createFilter(org.bson.conversions.Bson bson)
    Create a Tree object from a Bson filter.
    protected io.datatree.Tree
    elemMatch(String fieldName, io.datatree.Tree 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.
    protected io.datatree.Tree
    eq(String id)
    Creates a filter that matches all documents where the "_id" field equals the specified document identifier.
    protected io.datatree.Tree
    eq(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the field name equals the specified value.
    protected io.datatree.Tree
    exists(String fieldName)
    Creates a filter that matches all documents that either contain the given field.
    protected io.datatree.Tree
    expr(io.datatree.Tree expression)
    Allows the use of aggregation expressions within the query language.
    protected io.datatree.Tree
    geoIntersects(String fieldName, com.mongodb.client.model.geojson.Geometry geometry)
    Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
    protected io.datatree.Tree
    geoWithin(String fieldName, com.mongodb.client.model.geojson.Geometry geometry)
    Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
    protected io.datatree.Tree
    geoWithinBox(String fieldName, double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY)
    Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified box.
    protected io.datatree.Tree
    geoWithinCenter(String fieldName, double x, double y, double radius)
    Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified circle.
    protected io.datatree.Tree
    geoWithinPolygon(String fieldName, List<List<Double>> points)
    Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified polygon.
    protected io.datatree.Tree
    gt(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the given field is greater than the specified value.
    protected io.datatree.Tree
    gte(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value.
    protected io.datatree.Tree
    in(String fieldName, Object... values)
    Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
    protected io.datatree.Tree
    lt(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the given field is less than the specified value.
    protected io.datatree.Tree
    lte(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value.
    protected io.datatree.Tree
    mod(String fieldName, long divisor, long remainder)
    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).
    protected io.datatree.Tree
    ne(String fieldName, Object value)
    Creates a filter that matches all documents where the value of the field name does not equal the specified value.
    protected io.datatree.Tree
    near(String fieldName, com.mongodb.client.model.geojson.Point geometry, Double maxDistance, Double minDistance)
    Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
    protected io.datatree.Tree
    nin(String fieldName, Object... values)
    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.
    protected io.datatree.Tree
    nor(io.datatree.Tree... filters)
    Creates a filter that performs a logical NOR operation on all the specified filters.
    protected io.datatree.Tree
    not(io.datatree.Tree filter)
    Creates a filter that matches all documents that do not match the passed in filter.
    protected io.datatree.Tree
    notExists(String fieldName)
    Creates a filter that matches all documents that either do not contain the given field.
    protected io.datatree.Tree
    or(io.datatree.Tree... filters)
    Creates a filter that preforms a logical OR of the provided list of filters.
    protected io.datatree.Tree
    regex(String fieldName, String pattern)
    Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
    protected io.datatree.Tree
    regex(String fieldName, String pattern, String options)
    Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
    protected io.datatree.Tree
    size(String fieldName, int size)
    Creates a filter that matches all documents where the value of a field is an array of the specified size.
    protected io.datatree.Tree
    text(String search)
    Creates a filter that matches all documents matching the given search term.
    protected io.datatree.Tree
    text(String search, com.mongodb.client.model.TextSearchOptions options)
    Creates a filter that matches all documents matching the given the search term with the given text search options.
    protected org.bson.conversions.Bson
    toBson(io.datatree.Tree tree)
    Converts Tree object to Bson object.
    protected io.datatree.Tree
    where(String javaScriptExpression)
    Creates a filter that matches all documents for which the given expression is true.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MongoFilters

      public MongoFilters()
  • Method Details

    • or

      protected io.datatree.Tree or(io.datatree.Tree... filters)
      Creates a filter that preforms a logical OR of the provided list of filters.
      Parameters:
      filters - the list of filters to and together
      Returns:
      the filter
    • and

      protected io.datatree.Tree and(io.datatree.Tree... 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}}
      
      Parameters:
      filters - the list of filters to and together
      Returns:
      the filter
    • all

      protected io.datatree.Tree all(String fieldName, Object... values)
      Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
      Parameters:
      fieldName - the field name
      values - the list of values
      Returns:
      the filter
    • nor

      protected io.datatree.Tree nor(io.datatree.Tree... filters)
      Creates a filter that performs a logical NOR operation on all the specified filters.
      Parameters:
      filters - the list of values
      Returns:
      the filter
    • not

      protected io.datatree.Tree not(io.datatree.Tree 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}}
      
      Parameters:
      filter - the value
      Returns:
      the filter
    • eq

      protected io.datatree.Tree eq(String id)
      Creates a filter that matches all documents where the "_id" field equals the specified document identifier.
      Parameters:
      id - document identifier (value of the "_id" field)
      Returns:
      the filter
    • eq

      protected io.datatree.Tree eq(String fieldName, Object 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.
      Parameters:
      fieldName - the field name
      value - the value, which may be null
      Returns:
      the filter
    • ne

      protected io.datatree.Tree ne(String fieldName, Object value)
      Creates a filter that matches all documents where the value of the field name does not equal the specified value.
      Parameters:
      fieldName - the field name
      value - the value, which may be null
      Returns:
      the filter
    • in

      protected io.datatree.Tree in(String fieldName, Object... values)
      Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
      Parameters:
      fieldName - the field name
      values - the list of values
      Returns:
      the filter
    • nin

      protected io.datatree.Tree nin(String fieldName, Object... values)
      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.
      Parameters:
      fieldName - the field name
      values - the list of values
      Returns:
      the filter
    • lt

      protected io.datatree.Tree lt(String fieldName, Object value)
      Creates a filter that matches all documents where the value of the given field is less than the specified value.
      Parameters:
      fieldName - the field name
      value - the value
      Returns:
      the filter
    • lte

      protected io.datatree.Tree lte(String fieldName, Object value)
      Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value.
      Parameters:
      fieldName - the field name
      value - the value
      Returns:
      the filter
    • gt

      protected io.datatree.Tree gt(String fieldName, Object value)
      Creates a filter that matches all documents where the value of the given field is greater than the specified value.
      Parameters:
      fieldName - the field name
      value - the value
      Returns:
      the filter
    • gte

      protected io.datatree.Tree gte(String fieldName, Object value)
      Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value.
      Parameters:
      fieldName - the field name
      value - the value
      Returns:
      the filter
    • exists

      protected io.datatree.Tree exists(String fieldName)
      Creates a filter that matches all documents that either contain the given field.
      Parameters:
      fieldName - the field name
      Returns:
      the filter
    • notExists

      protected io.datatree.Tree notExists(String fieldName)
      Creates a filter that matches all documents that either do not contain the given field.
      Parameters:
      fieldName - the field name
      Returns:
      the filter
    • regex

      protected io.datatree.Tree regex(String fieldName, String pattern)
      Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
      Parameters:
      fieldName - the field name
      pattern - the pattern
      Returns:
      the filter
    • regex

      protected io.datatree.Tree regex(String fieldName, String pattern, String options)
      Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.
      Parameters:
      fieldName - the field name
      pattern - the pattern
      options - the options
      Returns:
      the filter
    • where

      protected io.datatree.Tree where(String javaScriptExpression)
      Creates a filter that matches all documents for which the given expression is true.
      Parameters:
      javaScriptExpression - the JavaScript expression
      Returns:
      the filter
    • elemMatch

      protected io.datatree.Tree elemMatch(String fieldName, io.datatree.Tree 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.
      Parameters:
      fieldName - the field name
      filter - the filter to apply to each element
      Returns:
      the filter
    • expr

      protected io.datatree.Tree expr(io.datatree.Tree expression)
      Allows the use of aggregation expressions within the query language.
      Parameters:
      expression - the aggregation expression
      Returns:
      the filter
    • text

      protected io.datatree.Tree text(String search)
      Creates a filter that matches all documents matching the given search term.
      Parameters:
      search - the search term
      Returns:
      the filter
    • text

      protected io.datatree.Tree text(String search, com.mongodb.client.model.TextSearchOptions options)
      Creates a filter that matches all documents matching the given the search term with the given text search options.
      Parameters:
      search - the search term
      options - the text search options to use
      Returns:
      the filter
    • geoIntersects

      protected io.datatree.Tree geoIntersects(String fieldName, com.mongodb.client.model.geojson.Geometry geometry)
      Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
      Parameters:
      fieldName - the field name
      geometry - the bounding GeoJSON geometry object
      Returns:
      the filter
    • geoWithin

      protected io.datatree.Tree geoWithin(String fieldName, com.mongodb.client.model.geojson.Geometry geometry)
      Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
      Parameters:
      fieldName - the field name
      geometry - the bounding GeoJSON geometry object
      Returns:
      the filter
    • geoWithinBox

      protected io.datatree.Tree geoWithinBox(String fieldName, double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY)
      Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified box.
      Parameters:
      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
    • geoWithinCenter

      protected io.datatree.Tree geoWithinCenter(String fieldName, double x, double y, double radius)
      Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified circle.
      Parameters:
      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
    • geoWithinPolygon

      protected io.datatree.Tree geoWithinPolygon(String fieldName, List<List<Double>> points)
      Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified polygon.
      Parameters:
      fieldName - the field name
      points - a list of pairs of x, y coordinates. Any extra dimensions are ignored
      Returns:
      the filter
    • mod

      protected io.datatree.Tree mod(String fieldName, long divisor, long remainder)
      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).
      Parameters:
      fieldName - the field name
      divisor - the modulus
      remainder - the remainder
      Returns:
      the filter
    • near

      protected io.datatree.Tree near(String fieldName, com.mongodb.client.model.geojson.Point geometry, Double maxDistance, Double minDistance)
      Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
      Parameters:
      fieldName - the field name
      geometry - the bounding GeoJSON geometry object
      maxDistance - the maximum distance from the point, in meters. It may be null.
      minDistance - the minimum distance from the point, in meters. It may be null.
      Returns:
      the filter
    • size

      protected io.datatree.Tree size(String fieldName, int size)
      Creates a filter that matches all documents where the value of a field is an array of the specified size.
      Parameters:
      fieldName - the field name
      size - the size of the array
      Returns:
      the filter
    • createFilter

      protected io.datatree.Tree createFilter(org.bson.conversions.Bson bson)
      Create a Tree object from a Bson filter.
      Parameters:
      bson - input Bson
      Returns:
      the filter
    • toBson

      protected org.bson.conversions.Bson toBson(io.datatree.Tree tree)
      Converts Tree object to Bson object.
      Parameters:
      tree - input Tree object
      Returns:
      the Bson