go ahead... be a heretic | |
PerlMonks |
(OT) Perl and creating a query for MongoDBby ovedpo15 (Pilgrim) |
on Jul 30, 2019 at 11:10 UTC ( [id://11103616]=perlquestion: print w/replies, xml ) | Need Help?? |
ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
I'm working with Perl and MongoDB but I have a direct question about querying so I hope someone here can help. I have created the following report with Perl:
As you can see, I have all_data level which contains an array of objects that each one of them contains sub_data array and all_data_name and all_data_path fields. The sub_data is an array of object where each one of them contains the sub_name, sub_path and info object. My goal is to create a query which gets all reports with the name "test1" and the username "erwerwcsd" (I guess we need to use $match). Then I want to combine those reports in the following way: Merge all reports (implementation could be different) into one main report and remove duplicates by the timestamp so only the late blocks will remain. In other to explain it, I will use the following example: (I marked it as all_data<index> and sub_data<index>) First report: (all_data<index> Second report: Third report: Fourth report: Fifth report: Then the merge will be as follows: Merge of first and second: (Explanation: they have same all_data_name and all_data_path but not sub_name and sub_path) Merge of first and third: (Explanation: will be same as the first report because we take the latest. In that case they have same all_data, same sub_data and same info level) Merge of first and fourth: (Explanation: In that case they have same all_data, same sub_data and but not same info level) Merge of first and fifth: (Explanation: they have different all_data_name) Because of the multi nesting It feels like not efficient to just iterate over each block and also I'm not sure which query operators I should use for that. I'm looking for a way of combining those reports into one main report (at least just to understand the logic). I hope my question is readable and not so hard to understand (tried to show all possible cases). Thank you. EDIT: I understood that I should not do those operations from Mongo side and better to just get the needed reports and create the wanted report with Perl. So I will get all the reports and put into a hash. Then I should iterate through the first and second arrays. Those arrays can be very big so I feel like it is not so efficient. I would love to hear some suggestion on how to look at this problem, some interesting efficient way. Thank you all!
Back to
Seekers of Perl Wisdom
|
|