I am trying to get data from mongodb using perl, but I get undefined value for variable $people
my $client = MongoDB::MongoClient->new(host =>
'mongodb://xxx.xxx.xxx.xxx',port=>27017, username => 'xxxx',
password => 'xxxx');
my $db = $client->get_database("xxx");
my $collection = $db->get_collection("xxx");
my $people = $collection->find_one({"transactionid" => $id});
while (my $p = $people->next) {
print Dumper $p;
}
and I want to get this data :
{
"_id" : ObjectId("5c453500e2fb4adc98e9fa84"),
"transactionid" : NumberLong(45282),
"transactionbillerid" : NumberLong(43137),
"requesttime" : ISODate("2019-01-21T02:57:04.923Z"),
"requestmessage" : "xxxxxxxx",
"responsetime" : ISODate("2019-01-21T02:57:05.236Z"),
"responsemessage" : "xxx"
}
any suggestions, is there something wrong with my code ?
$iddoes not have the value you think it has, or there is no element in your collection with thetransactionidyou're looking for,my $id = $query->param('trx_id');and there is element in my collection withtransactionidI'm looking for :D$idset to a hardcoded value? Trymy $id = '1234';(or whatever the value is) to see if it works. Also,->find_onedoes not return an iterator but the document itself.