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

$allOrdered / $contains query operations for arrays

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Query Execution

      It could be helpful to provide a new operator, similar to $all for arrays, that matches an ordered subset of items:


      {'actions': [2, 6, 3, 8, 5, 3]}


      {'actions': [6, 4, 2, 8, 4, 3]}

      // This should find the first document, but not the second as only the first contains [6, 3, 8] in order
      db.test.find({'actions': {'$contains': [6, 3, 8]}});

      { "_id" : ObjectId("4b993df679e2022d6d0086f3"), 'actions' : [2, 6, 3, 8, 5, 3] }

      A couple of use cases:

      • Phrase matching in full-text search (storing stemmed terms as strings in an array)
      • Finding users on a website that have performed a certain sequence of actions

      Also, allowing it to be optionally anchored to the start or end of an array would open up more possibilities:

      • Storing paths to files as individual segments of the path (by splitting the path by '/'), then finding files under a certain directory
        (or more generically, querying on items that have a list that is a path in a tree/hierarchy or a graph).

            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            hmarr Harry Marr
            1 Vote for this issue
            5 Start watching this issue