Search code examples
mongodbslamdata

Slamdata Query Nested Arrays


I have the below code as part of a mongodb document that I am querying with Slamdata v4.0:

"services" : [
    {
        "serviceline101" : {
            "Name" : "Brake Inspection",
            "Part_Number" : "",
            "QTY" : "6",
            "Notes" : ""
        },
        "serviceline102" : {
            "Name" : "Oil Samples",
            "Part_Number" : "",
            "QTY" : "1",
            "Notes" : ""
        },
        "serviceline103" : {
            "Name" : "Inspection",
            "Part_Number" : "",
            "QTY" : "1",
            "Notes" : ""
        },

What I need to do is to be able to query against the second layer of nested data in "services".

I can get to this data for one object by using

services[*] 

or for one object in the array:

services[*].serviceline1.Part_Number

for instance.

What I am trying to find is a way for this engine to iterate through all objects in the services array down to Part_Number for each like (this doesn't work, just theory):

services[*].*.Part_Number

Any ideas? I don't even know if this is possible. I am currently getting around this by making a flat dataset for reporting purposes only and can continue doing, just trying to eliminate a step if I'm able.

Thanks!


Solution

  • You can use the following syntax to flatten the values in a document:

    services[*]{*}.Part_Number

    Hope that helps!