Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用perl从mongodb获取答案_Mongodb_Perl - Fatal编程技术网

用perl从mongodb获取答案

用perl从mongodb获取答案,mongodb,perl,Mongodb,Perl,我已经用Perl编写了从MongoDB获取答案的代码,但它不起作用。它总是给出上下文错误。我试图做的是根据MongoDB中的搜索条件获取结果 use strict; use warnings; use MongoDB; use Data::Dumper; sub answer_get { my $database = shift; my $database_collection = shift; my $msg = shift; my $client = MongoDB->connect

我已经用Perl编写了从MongoDB获取答案的代码,但它不起作用。它总是给出上下文错误。我试图做的是根据MongoDB中的搜索条件获取结果

use strict;
use warnings;
use MongoDB;
use Data::Dumper;

sub answer_get {
my $database = shift;
my $database_collection = shift;
my $msg = shift;
my $client = MongoDB->connect();
my $db = $client->get_database( 'tutorial' );
my $query_result = $db->get_collection( 'users' )->find({context: "what", 
keyword: "IP"},{"define":1});
}
my $get_answer = answer_get("tutorial", "users", "IP");
#print $get_answer;
输出

syntax error at mongoreply.pl line 15, near "context:"
Global symbol "$query_result" requires explicit package name (did you forget 
to declare "my $query_result"?) at mongoreply.pl line 21.
syntax error at mongoreply.pl line 25, near "}"
Execution of mongoreply.pl aborted due to compilation errors.
当我在MongoDB中运行它时,我得到了答案

db.users.find({context: "what", keyword: "IP"},{"define":1})
{ "_id" : ObjectId("5b4314bda763102504004ea1"), "define" : "An Internet 
Protocol address (IP address) is a numerical label assigned to each device 
connected to a computer network that uses the Internet Protocol for 
communication" }

我的要求是在define中获取语句,即我有

您得到的语法错误来自perl,与MongoDB无关。 要构建hashref,必须使用以下符号:

{
    key => value,
    other_key => other_value,
}

not
{“key”:“value”}
(看起来像JSON)。

您得到的语法错误来自perl,与MongoDB无关。 要构建hashref,必须使用以下符号:

{
    key => value,
    other_key => other_value,
}
not
{“key”:“value”}
(看起来像JSON)