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

aggregation array sort differs from query/index array sort; causes aggregation results to change depending on sort optimizations

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Query
    • ALL
    • Hide
      c = db.c;
      c.drop();
      
      c.save( { _id:'x', a:[ 2, 1 ] } );
      c.save( { _id:'y', a:[ 1, 2 ] } );
      
      // no index                                                                                    
      printjson( c.aggregate( { $sort:{ a:1 } } ) );
      
      // with index                                                                                  
      c.ensureIndex( { a:1 } );
      printjson( c.aggregate( { $sort:{ a:1 } } ) );
      
      Show
      c = db.c; c.drop(); c.save( { _id: 'x' , a:[ 2, 1 ] } ); c.save( { _id: 'y' , a:[ 1, 2 ] } ); // no index printjson( c.aggregate( { $sort:{ a:1 } } ) ); // with index c.ensureIndex( { a:1 } ); printjson( c.aggregate( { $sort:{ a:1 } } ) );

      Aggregation and queries/indexing sort arrays differently. This can cause the results returned by an aggregation to change when a sort stage is removed in favor of using an index.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: