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

Accessing array elements by position fails in $project

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.1.2
    • Component/s: Aggregation Framework
    • None
    • ALL

      Insert some data:
      db.foo.insert({title:"A doc", intervals:[

      {value:1, x:"a"}

      ,

      {value:2,x:"b"}

      ,

      {value:3,x:"c"}

      ]});

      Verify it's there:
      db.foo.find()
      { "_id" : ObjectId("4fd776800821eeb296a71a70"), "title" : "A doc", "intervals" : [

      {"value" : 1, "x" : "a"}

      ,

      {"value" : 2, "x" : "b"}

      ,

      {"value" : 3, "x" : "c"}

      ] }

      Try a projection:
      db.foo.aggregate({$project:{title:1, i1:"$intervals.0"}})
      {
      "errmsg" : "exception: assertion src/mongo/db/pipeline/value.cpp:446",
      "code" : 0,
      "ok" : 0
      }

      Try another:
      db.foo.aggregate({$project:{title:1, i1:"$intervals.0.value"}})
      {
      "errmsg" : "exception: assertion src/mongo/db/pipeline/value.cpp:446",
      "code" : 0,
      "ok" : 0
      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            mweyant@enernoc.com Matt Weyant
            Votes:
            3 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: