Class MongoDBWeekdayOfDateFunction

java.lang.Object
com.kingsrook.qqq.backend.module.mongodb.fieldfunctions.MongoDBWeekdayOfDateFunction
All Implemented Interfaces:
BackendFieldFunctionAdapterInterface, MongoDBFieldFunctionAdapterInterface, Serializable

public class MongoDBWeekdayOfDateFunction extends Object implements MongoDBFieldFunctionAdapterInterface
MongoDB adapter for WeekdayOfDateFunction. MongoDB $dayOfWeek returns Sun=1..Sat=7. ISO-8601 needs Mon=1..Sun=7. Conversion: ((mongoDow + 5) % 7) + 1 For ORDER BY with sortSundayFirst=true: isoValue % 7 so Sunday(7) becomes 0 and sorts before Monday(1).
See Also:
  • Constructor Details

    • MongoDBWeekdayOfDateFunction

      public MongoDBWeekdayOfDateFunction()
  • Method Details

    • getExpression

      public Object getExpression(String fieldReference, FieldFunction fieldFunction, Function<String,String> fieldNameToFieldReference)
      Description copied from interface: MongoDBFieldFunctionAdapterInterface
      Returns a MongoDB aggregation expression for the given field reference. The fieldReference is a "$"-prefixed field name (e.g., "$firstName").
      Specified by:
      getExpression in interface MongoDBFieldFunctionAdapterInterface
      Parameters:
      fieldReference - "$"-prefixed field name for the function's source field.
      fieldFunction - the function with arguments.
      fieldNameToFieldReference - resolves a QQQ field name to its "$"-prefixed MongoDB field reference (e.g., "timeZone" → "$time_zone"). Useful when the function expression needs to reference additional fields on the same document (e.g., a per-row timezone field).
    • getExpressionForOrderBy

      public Object getExpressionForOrderBy(String fieldReference, FieldFunction fieldFunction, Function<String,String> fieldNameToFieldReference)
      Description copied from interface: MongoDBFieldFunctionAdapterInterface
      Returns a MongoDB aggregation expression for use specifically in $sort stages. Defaults to getExpression(); may be overridden when the sort form differs (e.g., a modulo for Sunday-first weekday sorting).
      Specified by:
      getExpressionForOrderBy in interface MongoDBFieldFunctionAdapterInterface
    • buildIsoExpression

      protected Object buildIsoExpression(String fieldReference)
      Build the ISO-8601 weekday expression from a MongoDB $dayOfWeek value. MongoDB: Sun=1, Mon=2, ..., Sat=7 ISO: Mon=1, Tue=2, ..., Sun=7 Formula: ((mongoDow + 5) % 7) + 1