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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • 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 } } ) );

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: