In the context of metabase:
I am applying the following one-liner query to extract a particular field from a collection of mongodb documents:
[{"$project":{"myName":"$field1.field2" }},
{"$match":{"_id":{"$eq":"blah"}}} ]
myName is a string field that is in fact a serialized JSON object.
How can I adapt the pipeline above, perhaps using JSON.parse(), to pull out fields nested further down the JSON hierarchy?
Part II: How would I add a final step to extract some of those deeply nested fields? The situation is further complicated because the document structure is not consistent between documents...
Thanks!
JSON.parse()before you stored it? Because if you did, then MongoDB can manipulate it just like any other document. But not as a "string". This really sounds more like a hangover from an RDBMS implementation that should have been converted earlier.$unwindas the very first pipeline stage is very wasteful. You should almost always begin with$match.