Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1179

aggregation query cursor returning results in reverse order.

    • Type: Icon: Task Task
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 1.0.6
    • Component/s: None
    • Labels:
    • Environment:
      ubuntu

      My aggregation pipeline on mongoDB is like.

      db.assets.aggregate([{"$match":{"$or":[{"albums":{"$elemMatch":{"id":"78c72b85944e5085a4a3be77a2d175fe","order":{"$gt":"C2"}}}},{"albums":{"$elemMatch":{"id":"18f292072b7555965e0f61a0331a3a43","order":{"$gt":"C2"}}}}]}}
      ,

      {"$unwind":"$albums"}

      ,
      {"$sort":{"albums.order":1,"created":1}},
      {"$group":{"_id":"$albums.id","assets":

      {"$push":"$$ROOT"}

      }},
      {"$project":{"assets":

      {"$slice":["$assets",6]}

      }}])

      my asset collection having entries like.

      {
      "_id": "8ed6dc473e331d895ecbdea7f9bbd55e",
      "created": 1479463428837247,
      "updated": 1479463428837247,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":[

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "D1" }

      ,]
      },
      {
      "_id": "aec701d23dfe5f3a100d678e1a04f716",
      "created": 1479463428902155,
      "updated": 1479463428902155,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums": [

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "D2" }

      ,]
      },
      {
      "_id": "b2fe8f9dcf8f3f92f6396cfa574ef71c",
      "created": 1479463428971650,
      "updated": 1479463428971650,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums": [

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "E1" }

      ,]
      },
      {
      "_id": "050b550fb23bf780f93eec43cbc667f1",
      "created": 1479463428065297,
      "updated": 1479463428065297,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":[

      { "id": "78c72b85944e5085a4a3be77a2d175fe", "order": "D1" }

      ,]
      },
      {
      "_id": "dc54279bc0318f41808b65d1fe7142b2",
      "created": 1479463428134560,
      "updated": 1479463428134560,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":[

      { "id": "78c72b85944e5085a4a3be77a2d175fe", "order": "D2" }

      ,]
      }
      my result returned is something like.

      [
      {
      '_id': '18f292072b7555965e0f61a0331a3a43',
      assets: [
      {
      "_id": "8ed6dc473e331d895ecbdea7f9bbd55e",
      "created": 1479463428837247,
      "updated": 1479463428837247,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "D1" }

      },
      {
      "_id": "aec701d23dfe5f3a100d678e1a04f716",
      "created": 1479463428902155,
      "updated": 1479463428902155,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "D2" }

      },
      {
      "_id": "b2fe8f9dcf8f3f92f6396cfa574ef71c",
      "created": 1479463428971650,
      "updated": 1479463428971650,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":

      { "id": "18f292072b7555965e0f61a0331a3a43", "order": "E1" }

      }
      ],
      {
      "_id": "78c72b85944e5085a4a3be77a2d175fe",
      "assets": [
      {
      "_id": "050b550fb23bf780f93eec43cbc667f1",
      "created": 1479463428065297,
      "updated": 1479463428065297,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":

      { "id": "78c72b85944e5085a4a3be77a2d175fe", "order": "D1" }

      },
      {
      "_id": "dc54279bc0318f41808b65d1fe7142b2",
      "created": 1479463428134560,
      "updated": 1479463428134560,
      "catalog_id": "4b5ce056175151e3f0aa1741eedb7f12",
      "albums":

      { "id": "78c72b85944e5085a4a3be77a2d175fe", "order": "D2" }

      }
      ]
      }
      ]
      result returned from the query cursor is not in the same order for album as passed in the match query with or. 78c72b85944e5085a4a3be77a2d175fe is coming after 18f292072b7555965e0f61a0331a3a43. ideally it should be in the same order it is passed to the query.

            Assignee:
            Unassigned Unassigned
            Reporter:
            wsourabh sourabh jain
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: