ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:

i have some data in Mongo. I want to get keys from that like  keys $data{$date}{$err_id}{'Total_calls'} It works in perl hash. But how to get that from Mongo. I tried like this but not working.

for (my $priday=int($day); $priday >=1 ; $priday--) { my $old_print_date=sprintf('%02d-%02d-%04d',$priday,$month,$year); $date = sprintf('%02d%02d%04d',$priday,$month,$year); my $data = $collection->find({'date' => "$old_print_date"}); while (my $doc = $data->next) { $row = 1; $worksheet->write( $row, $col, sprintf('%0d', $doc{$da +te}{'Total'}{"305"}), $format2); $row++; $worksheet->write( $row, $col, sprintf('%0d', $doc{$da +te}{'Pre'}{"305"}), $format2); $row++; $worksheet->write( $row, $col, sprintf('%0d', $doc{$da +te}{'Post'}{"305"}), $format2); $row++; } }

Sample data

'27112015' => { '25' => { 'Total_calls' => { '11' => 11, '21' => 13, '17' => 44, '02' => 1, '22' => 18, '18' => 29, '08' => 11, '23' => 8, '16' => 22, '13' => 30, '06' => 1, '01' => 3, '12' => 20, '20' => 28, '14' => 18, '15' => 17, '07' => 2, '10' => 30, '19' => 28, '09' => 7 } }, 'Total' => { '25' => 341, '305' => 23 }, 'Post' => { '25' => 216, '305' => 23 }, 'Pre' => { '25' => 125 }, '305' => { 'Total_calls' => { '11' => 13, '15' => 10 } } }, 'date' => '27-11-2015'

Replies are listed 'Best First'.
Re: Getting keys from Mongo DB
by ww (Archbishop) on Jan 11, 2016 at 14:59 UTC

    You may find some useful notions in this SO node but you'll likely do even better by reading Mongo's documentation itself.


    Spirit of the Monastery

    Yet another gimmé request!
    Sorry, we expect SOPW to seek wisdom, not to ask us to do so for them.