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

Array in input doc schema incorrectly affects $project output

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Won't Fix
    • None
    • None
    • Aggregation Framework
    • None
    • Fully Compatible
    • ALL

    Description

      An array in an input doc can cause unexpected behavior when $project-ing a computed value within an output field of the same name.

      Test:

      c = db.c;
       
      // Note the $sort stages are required so the document source cursor includes 'a' in its Project.
       
      c.drop();
      c.save( { a:[ {}, {}, {} ], x:'bar' } );
      printjson( c.aggregate( { $sort:{ a:1 } }, { $project:{ a:{ c:'$x' } } } ).toArray() );
       
      c.drop();
      c.save( { a:[ 1, 2, 3 ], x:'bar' } );
      printjson( c.aggregate( { $sort:{ a:1 } }, { $project:{ a:{ c:'$x' } } } ).toArray() );
      

      Output

      Aaron-Staples-MacBook-Pro:mongo8 aaron$ ./mongo test.js
      MongoDB shell version: 2.2.0-rc1-pre-
      connecting to: test
      {
      	"result" : [
      		{
      			"_id" : ObjectId("501dc1a903c33b9898335417"),
      			"a" : [
      				{
      					"c" : "bar"
      				},
      				{
      					"c" : "bar"
      				},
      				{
      					"c" : "bar"
      				}
      			]
      		}
      	],
      	"ok" : 1
      }
      {
      	"result" : [
      		{
      			"_id" : ObjectId("501dc1a903c33b9898335418"),
      			"a" : [ ]
      		}
      	],
      	"ok" : 1
      }
      

      Expected output:

      Aaron-Staples-MacBook-Pro:mongo8 aaron$ ./mongo test.js
      MongoDB shell version: 2.2.0-rc1-pre-
      connecting to: test
      {
      	"result" : [
      		{
      			"_id" : ObjectId("501dc1d8aba874295f450cf6"),
      			"a" : {
      				"c" : "bar"
      			}
      		}
      	],
      	"ok" : 1
      }
      {
      	"result" : [
      		{
      			"_id" : ObjectId("501dc1d8aba874295f450cf7"),
      			"a" : {
      				"c" : "bar"
      			}
      		}
      	],
      	"ok" : 1
      }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: