I'm wondering if it is possible to express any 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.
Any idea how to achieve the described XPath effect?
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)
MongoDB core developers: What do you think? 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?
Thanks,
mongonix
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>
I had look at jFunk. Seems nice, but a bit oversimplified eventually.
One thing to keep in mind is how to execute these queries
effectively.
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 I guess implementing such queries effectively
would require new kinds of (additional) indexing, unless you want to
iterate over all entries and check each one for the required sub-
trees.
> An easy first idea might just be wildcard operator a.*b
Do you mean the first step to support it in the future MongoDB
version?
Or is this start-expression syntax avilable already?