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

Order of responses to a MongoDB $in query

    Details

    • Backwards Compatibility:
      Fully Compatible

      Description

      I have a use-case where I am querying an array of ObjectIDs. For example:

      db.things.find({
      _id:

      { $in: [ ObjectID(...), ObjectID(...), ObjectID(...), ObjectID(...) ] }

      })

      I'd like the results to be ordered by `_id.$in`. Right now I'm resorting to client-side sorting, which kind of sucks since it requires converting between ObjectIDs and strings among other hacks.

      A special sorting option like this would be awesome (similar to $natural):

      db.things.find({}).sort({
      $in:

      { '_ids' }

      })

      Although the attribute being `$in`ed need not be `_id`, it should be unique (and thus indexed).

      Some related questions on StackOverflow:

      http://stackoverflow.com/questions/3142260/order-of-responses-to-mongodb-in-query
      http://stackoverflow.com/questions/11839515/comparing-and-sorting-mongodb-objectids-in-node-convert-to-string

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                20 Vote for this issue
                Watchers:
                21 Start watching this issue

                Dates

                • Created:
                  Updated: