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

`$unwind` doesn't work on array subdocument fields

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.2
    • Component/s: None
    • ALL
    • Hide
      1. db.collection.insertOne({

        items: [

          {

            _id: ObjectId,

            name: 'foobar'

      {{    }}}

        ]

      });

      1. db.collection.aggregate([
          {
            $unwind: }}{{'$items.name'
        {{  }}}
        ]);{{}}

      Outputs nothing

      Show
      db.collection.insertOne({   items: [     {       _id: ObjectId,       name: 'foobar' {{    }}}   ] }); db.collection.aggregate([   {     $unwind: }}{{'$items.name' {{  }}} ]); {{}} Outputs nothing

      Given the following document:

      db.collection.insertOne({

        items: [

          {

            _id: ObjectId,

            name: 'foobar'

      {{    }}}

        ]

      });

      Trying to `$unwind` the field path `$items.name` outputs nothing.

      On the other hand, the output of this:

      db.collection.aggregate([
        {
          $project: {
      {{      type: { $type: '$items.name' }}}
      {{    }}}
      {{  }}}
      ]);

      is the following:

      {{{}}
        "_id" : ObjectId("..."),
        "type" : "array"
      }

      If the expression `$items.name` resolves to an array then why can I not `$unwind` this field path?

            Assignee:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Reporter:
            amitbeck@gmail.com Amit Beckenstein
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: