如何从Perl中的mongoDB返回数据?
发布时间:2020-12-15 22:02:53 所属栏目:大数据 来源:网络整理
导读:我读了 http://api.mongodb.org/perl/current/MongoDB/Examples.html,似乎只是来自Perl上mongoDB的文档.如何从perl中的mongoDB获取查询结果.让我们对Hash说.到目前为止,我已成功连接到数据库.我设法插入集合.现在我如何发出选择查询并将其返回的数据转换为哈
我读了
http://api.mongodb.org/perl/current/MongoDB/Examples.html,似乎只是来自Perl上mongoDB的文档.如何从perl中的mongoDB获取查询结果.让我们对Hash说.到目前为止,我已成功连接到数据库.我设法插入集合.现在我如何发出选择查询并将其返回的数据转换为哈希或类似的东西?
更新: Example of my data { "_id" : ObjectId("asdhgajsdghajgh"),"country" : "USA" "city" : "Boston" } { "_id" : ObjectId("asdhgajsdghajgh"),"country" : "USA" "city" : "Seattle" } { "_id" : ObjectId("asdhgajsdghajgh"),"country" : "Canada" "city" : "Calgary" } My code my $cursor = $my_collection ->find({ country => 1 }) ; while (my $row = $cursor->next) { print "$rown"; } 此代码不会产生任何输出. 解决方法
那不是官方文件.前往CPAN:
> MongoDB::Tutorial 迭代结果与DBI方式非常相似: use Data::Printer; use MongoDB; # no query is performed on initialization! my $cursor = $collection ->find({ active => 1,country => 'Canada' }) # filter "active" records from Canada ->sort({ stamp => -1 }) # order by "stamp" attribute,desc. ->limit(1000); # first 1000 records # query & iterate while (my $row = $cur->next) { # it is 'p',from Data::Printer! p $row; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |