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

Support for XPath like queries

    • Query Optimization

      It would be very nice to be able to express XPath-like queries with MongoDB.

      For example, let's say there is a JSON document that contains a certain subtree, but it is not known where it is inside the JSON
      document.

      In the XML world, one could use XPath and write something like this to
      express relative path (which returns all sub-trees matching the
      pattern):
      //tree_root_node/subnode1/subnode2 and so on.
      But how can somethig like this expressed with MongoDB? According to the documentation found on Mongo web-site, it is only possible to use the following two syntaxes:
      1) {tree_root_node: { subnode1 :

      {subnode2 : ...}

      }}
      2)

      { 'tree_root_node.subnode1.subnode2': ...}


      in both cases, one needs to know the full path from the JSON document root to the subtree of interest. But it is not known in my case as I
      explained before.

      And, BTW, it would be really cool if generic XPath queries could be
      applied on JSON documents. There are some proposals for JSON based
      XPath:
      http://goessner.net/articles/JsonPath/
      http://bluelinecity.com/software/jpath/
      http://somewebguy.wordpress.com/tag/Query/
      http://www.hugoware.net/projects/jlinq

      (BTW, many XML databases do actually support XPath natively. They even opimize their indexing and storage backends for effective XPath queries evaluation)

      Is something like this planned for the future releases? How difficult would it be to implement something like this? Would it require additional, more detailed indexing for effective implementation?

      Of course, it is easy to provide support at the syntactic level using whatever syntax (jQuery-like, XPath like, etc) - there are enough libraries for that. But implementing such queries effectively would eventually require new kinds of (additional) indexing, unless you want to iterate over all entries and check each one for the required sub- trees.

      Proposal by Eliot: An easy first idea might just be wildcard operator a.*b

      Please see this mailing list thread for more information:
      http://groups.google.com/group/mongodb-user/browse_thread/thread/d359c8ed8eacddea

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            mongonix mongonix
            Votes:
            21 Vote for this issue
            Watchers:
            27 Start watching this issue

              Created:
              Updated: