Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6187

incorrect uassert message on attempt to subtract a date from a number

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • ALL

      Observed behavior: Attempt to subtract a date from a number triggers a uassert with the message "cannot subtract one date from another". Subtracting one date from another, meanwhile, seems to be allowed.

      Expected behavior: The assertion message should be consistent with the operation that is not allowed.

      It would also make sense to validate all date related subtraction cases to make sure the desired behavior is implemented / checked with assertions.

      Test:

      c = db.c;
      c.drop();
      
      c.save( {} );
      
      // Does not assert.
      printjson( c.aggregate( { $project:{ a:{ $subtract:[ new Date(), new Date() ] } } } ) );
      // Asserts claiming that one date cannot be subtracted from another.
      printjson( c.aggregate( { $project:{ a:{ $subtract:[ 1, new Date() ] } } } ) );
      

            Assignee:
            matt.dannenberg Matt Dannenberg
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: