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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: