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

Limiting data by $slice returns adjacent items in a dict.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • ALL

      When asking for just an array inside a dict, only that array is returned (good so far). However, when you ask for a slice of that array, other items in that dict are also returned.

      > db.a.save({_id:1, vals: {first:[1,2,3,], second:[1,2,3]}})
      > db.a.find()
      { "_id" : 1, "vals" :

      { "first" : [ 1, 2, 3 ], "second" : [ 1, 2, 3 ] }

      }
      > db.a.find({},{"vals.first":{$slice:2}})
      { "_id" : 1, "vals" :

      { "first" : [ 1, 2 ], "second" : [ 1, 2, 3 ] }

      }

      //I would have expected this to work... might call that a bug.

      > db.a.find({},{"vals.first":1, "vals.first":{$slice:2}})
      { "_id" : 1, "vals" :

      { "first" : [ 1, 2 ], "second" : [ 1, 2, 3 ] }

      }

      > db.a.find({},{"vals":0, "vals.first":{$slice:2}})
      { "_id" : 1, "vals" :

      { "first" : [ 1, 2 ] }

      }

      (thanks skot on the #mongodb IRC channel for the example)

            Assignee:
            Unassigned Unassigned
            Reporter:
            heewa Heewa Barfchin
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: