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

Partial matching for sub objects

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      Any

      Description

      There ought to be a way to partially match sub objects

      Let's say you want to match this record:{a:[

      {b:1,c:2,d:4}

      ,

      {b:2,c:3,d:5}

      ]}

      There is no simple way to partially map one of the objects that belongs to 'a'. If you do find({a:{b:1,c:2}}) currently, it will fail since sub objects must match exactly.

      There are few work arounds:

      You can match the sub object exactly, for example find({a:{b:1,c:2,d:4}}). This is far from ideal, because it means you have to know the format of your data before hand, which completely defeats the purpose of using a schemaless database.

      You can use dot notation instead of a subobject, for example match against find(

      {'a.b':1,'a.c':2}

      ). This will work, but it will also return incorrect results, for example find(

      {'a.b':1,'a.c':3}

      ) will also match our document.

      You can use a javascript function. This will return correct results, but It's also orders of magnitude slower in large collections, and requires maintaining the project in multiple languages. This approach also introduces an additional level of complexity that seems needless.

      You can combine the second and third work arounds to fix incorrect results, but it's still difficult to maintain. You can also check the results of the the second method in your project's language, which eliminates the problem of having to generate javascript, but still seems overly complex.

      Ideally you could partially match sub objects by use of a conditional operator something like this: find({a:{$partial_match:

      {b:1,c:2}

      }})

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              eliot Eliot Horowitz (Inactive)
              Reporter:
              zgavin Zachary Gavin
              Participants:
              Votes:
              17 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: