Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
MongoDB field is array, how do I iterate a list?
cgamiller
<p>I am querying a MongoDB datasource that is returning a single document. It has numerous subdocuments and many of them have arrays.</p>
<p> </p>
<p>When choosing a field with an array, I'd like to iterate over that array in a list or table and have the columns of the table be the fields of the array.</p>
<p> </p>
<p>For example, the selected field is: application.features[]</p>
<p> </p>
<p>The features array has "name" and "description" fields. I'd like a list of each of the feature names.</p>
<p> </p>
<p>Since the dataset returns 1 document, it only has a single row. I've done some research and not sure how to proceed.</p>
<p> </p>
<p>* Do I need to save the JSON string as a variable and use a scripted dataset to parse the JSON?</p>
<p> </p>
<p>* Is there an easier way to do this without using a scripted dataset?</p>
<p> </p>
<p>Thanks.</p>
Find more posts tagged with
Comments
mwilliams
If you're currently bringing in the array as a string, you could use a text control to parse this out into rows into an HTML table, though, I think I'd have to hear more from you. I'm also not sure how well this will work with your layout. A scripted data set might be the best way to go. You could also always log an enhancement request to allow for arrays to be split into rows within a data set.
cgamiller
<p>Michael -- Thanks for responding. Appreciate your insight.</p>
<p> </p>
<p>Could you help me understand how I might accomplish this? Your suggestion might be the perfect solution.</p>
<p> </p>
<p>An example string that is returned is "["Feature1", "Feature2"]" which is a javascript array of strings. (If I choose the application.features[].names field).</p>
<p> </p>
<p>Do I use javascript scripting in birt to parse the array as JSON and then write a loop? Any chance you can point me to an example?</p>
<p> </p>
<p>I think perhaps this is within reach but I'm looking for how to start parsing this into a HTML table (or maybe even an unordered list).</p>
<p> </p>
<p>Thanks.</p>
mwilliams
I thought you were saying it would come in as a string that you needed to parse. I guess I misunderstood the first post. I've not really ever tried to bring in a list as there isn't a data type for it. Have you been able to use the object once you got it into BIRT?
rafex
<p>Hi, when i create a dataset in Birt with mongodb I have a list, if a using this element in the Preview Result only see 1 row (my list have any register), this one rows show group for example:</p>
<p>["data 1","data 2","data 3"] in the same row,</p>
<p> </p>
<p>I need show in three rows to mapping my report.</p>
<p> </p>
<p>data 1</p>
<p>data 2</p>
<p>data 3</p>
<p> </p>
<p>Next i need insert this data in table into birt report</p>
<p> </p>
<p>Please help me to do it</p>
<p> </p>
<p>Thanks</p>