#!/usr/bin/perl use MongoDB; use MongoDB::OID; use Spreadsheet::ParseExcel; use Spreadsheet::XLSX; use Spreadsheet::Read; $date=$ARGV[0]; $date or $date=`date --date='1 day ago' +%d-%m-%Y`; chomp $date; my $file_path="/root/prac/packages/SDP_VAS_NQI-17-06-2015.xlsx"; my $workbook = ReadData($file_path,cells => 0 ); if(defined $workbook->[0]{'error'}) { print "Error occurred while processing $file_path:".$workbook->[0] +{'error'}."\n"; exit(-1); } my $worksheet = $workbook->[1]; my $max_rows = $worksheet->{'maxrow'}; my $max_cols = $worksheet->{'maxcol'}; for my $row_num (15..($max_rows)) { my $cell = $worksheet->{cell}[2][$row_num]; # same, unformatted if($date eq $cell) { my $sqi = $worksheet->{cell}[36][$row_num]; # same, unformatt +ed print "$sqi\n"; print "$cell\n"; print "$row_num\n"; break; } } chomp $sqi; $db_host="172.16.15.115"; $db_name="ravi"; $client = MongoDB::MongoClient->new(host => $db_host, port => 2701 +7); $database = $client->get_database( $db_name ); $data = $database->get_collection("SDP_SQI"); %insert_data_hourly=(); $insert_data_hourly{'date'}=$date; $insert_data_hourly{'SQI'}=$sqi; $id=$data->insert(\%insert_data_hourly);

Here I am trying to read a particular date data in the excel sheet and insert it into MongoDB. Here for my understanding I printed the values (column 36 of that date present, date & row of that date) all are giving correct values

97.327499999999986 15-06-2015 30

But the problem is in DB only. Its showing null in the place of data.

{ "_id" : ObjectId("55cd825c783d4e53ee307201"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd82ed783d4e55b22035c1"), "date" : "02-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd83a6783d4e582a085531"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd83fa783d4e58555cf201"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8457783d4e58c2363781"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd84de783d4e598e302711"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8644783d4e5a0667b1b1"), "date" : "06-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8684783d4e5a1e2ed1a1"), "date" : "15-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd86cb783d4e5a2c05b7b1"), "date" : "15-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8acb783d4e5f8d272f71"), "date" : "13-08-2015", + "SQI" : null } { "_id" : ObjectId("55cd8ae6783d4e5fa51b6e21"), "date" : "15-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8b6c783d4e601d19b791"), "date" : "15-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8c44783d4e604261e121"), "date" : "15-06-2015", + "SQI" : NumberLong(0) } { "_id" : ObjectId("55cd8cab783d4e6050106bc1"), "date" : "15-06-2015", + "SQI" : null } { "_id" : ObjectId("55cd8d08783d4e60653b84c1"), "date" : "27-05-2015", + "SQI" : null } { "_id" : ObjectId("55cdab74783d4e791c7b7531"), "date" : "13-08-2015", + "SQI" : null } { "_id" : ObjectId("55cdab96783d4e791f0321b1"), "date" : "15-06-2015", + "SQI" : null }

Note: The data field contains not the exact data its a formulae.  =SUMIF($C$14:$AH$14,"SubScore",C15:AH15) if there is any non-numeric values it shows #N/A. But even the values are displaying in the terminal the DB showing NULL. What is the problem???? Thanks for reply


In reply to Problem with inserting data into MongoDB by ravi45722

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.