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

ExpressionNary (and others) do not properly serialize constant expressions, can cause a valid expression on mongos to be unparsable or incorrect on shards.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.2
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      An object or string specified as a constant to an ExpressionNary may not be parsed as a constant on a shard. This is because ExpressionNary does not use requireExpression with addToBsonArray, so constants are not represented using $const.

      Test

      // Set up a sharding test.                                                                                                             
      s = new ShardingTest( "aggregation", 2, 0, 2 );
      s.adminCommand( { enablesharding:"test" } );
      s.adminCommand( { shardcollection:"test.data", key:{ _id:1 } } );
      s.stopBalancer()
      
      d = s.getDB( "test" );
      d.data.save( { dollar:false } );
      
      // Currently the shard will get $cond:[ '$dollar', '$1.00', '$.99' ] and treat the second and third arguments as field paths.
      result = d.data.aggregate( { $project:{ _id:0, cost:{ $cond:[ '$dollar', { $const:'$1.00' }, { $const:'$.99' } ] } } } );
      
      printjson( result );
      assert.eq( [ { cost:'$.99' } ], result.result );
      
      s.stop();
      

      When fixing this we should also do a general audit for other cases that do not serialize properly.

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

              Created:
              Updated:
              Resolved: