The situation that I have is that I am querying MongoDB with a string for a field with more than one level in the hierarchy of objects. This query should be a string. So, for example, I request something like this in Groovy:
def queryField = 'abc' //this is variable and can be different every time def result = mongodb.collection.findOne([queryField:5])
The problem does not arise that as a result I want to find the value of the nested field. With GPath, I could go one level and get the value
def aObj = result."a" //or result["a"]
However, I want to delve into this by doing something like this:
def queryField = "abc" //this can change every time and is not always 'abc' def cObj = result[queryField] //since field is variable, can't just assume result.abc
This is not working in Groovy right now. There is an error recorded here , but I was wondering if there is a more efficient work for this scenario, which is a little cleaner than my parsing string, breaking into a point, and then building a traversal of the object. Note that "abc" is variable and unknown at run time (for example, it may be "abd").
Scott source share