我的应用每次包含“使用MongoDB”时都会崩溃在我的perl应用程序文件中。
我已经成功安装了MongoDB。我可以检查我的数据库使用其中一个,检查集合,创建新集合,所有这些都来自shell。
如果我尝试从mojolicious应用程序连接到mongoDb,如:
!/usr/bin/env perl
use Mojolicious::Lite;
use MongoDB;
use MongoDB::OID;
my $mongo_port = shift || 27017;
helper 'mongo' => sub {
my ($self, $name) = @_;
my $host = 'localhost:' . $mongo_port;
my $conn = MongoDB::MongoClient->new(host => $host);
my $db = $conn->get_database('test');
};
helper 'value2oid' => sub {
my ($self, $value) = @_;
MongoDB::OID->new($value);
};
如果我有一个有效的应用程序,并且包括:
Use MongoDB;
我明白了:
Can't load application from file "/Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl": Can't locate MongoDB.pm in @INC (you may need to install the MongoDB module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl line 4.
BEGIN failed--compilation aborted at /Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl line 4.
我对mongo,mojolicious和perl完全陌生,所以我想我没有安装一些软件包?
MongoDB文件(mongo,mongod ....)是否必须在mojolicious项目中?
不确定我缺少什么,所有文档都是从使用“使用MongoDB”开始的。在mojolicious应用程序内,所以不知道该怎么做。
希望有人可以指出我错过了什么。
答案 0 :(得分:1)
安装模块:
cpanm Mojolicious::Plugin::Mongodb
修正以下问题:
Can't write to /Library/Perl/5.18 and /usr/local/bin: Installing modules to /Users/eevitomperi/perl5
! To turn off this warning, you have to do one of the following:
! - run me as a root or with --sudo option (to install to /Library/Perl/5.18 and /usr/local/bin)
! - Configure local::lib your existing local::lib in this shell to set PERL_MM_OPT etc.
! - Install local::lib by running the following commands
通过运行:
cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
现在我可以从mojolicious
连接到Mongo