[英]can't get data from mongodb using perl (get undefined value)
我正在嘗試使用 perl 從 mongodb 獲取數據,但是我得到了變量$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;
}
我想得到這個數據:
{
"_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"
}
任何建議,我的代碼有問題嗎?
我認為您誤解了find_one()
返回的值。 名稱中有一個重要線索,但find_one()
返回單個記錄,而不是迭代器。
顯然,我無權訪問您的數據,因此我無法確認這一點,但我希望您可以通過運行以下代碼獲得所需內容:
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 $person = $collection->find_one({"transactionid" => $id});
print Dumper $person;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.