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

Find on view with sort through mongos may incorrectly return empty result set

    XMLWordPrintable

Details

    • Fully Compatible
    • ALL
    • Query 2016-12-12

    Description

      A find() with a sort() on a mongos may return an empty result set:

      mongos> db.c.insert({x:1})
      WriteResult({ "nInserted" : 1 })
      mongos> db.c.find()
      { "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }
      mongos> db.createView("cView", "c", [{$match : { x : {$gt : 0}}}])
      { "ok" : 1 }
      mongos> db.cView.find()
      { "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }
      mongos> db.cView.find().sort({_id:1})
      

      There's a simple workaround, which is to use the aggregation pipeline:

      mongos> db.cView.aggregate([{ $sort: {_id:1}}])
      { "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }
      

      Attachments

        Issue Links

          Activity

            People

              kyle.suarez@mongodb.com Kyle Suarez
              kyle.suarez@mongodb.com Kyle Suarez
              Votes:
              0 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: