Mojolicious + MongoDB:找不到 MongoDB.pm 错误



我的应用程序每次在我的perl应用程序文件中包含"use MongoDB;"时都会崩溃。

我已经成功安装了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项目中?

不确定我错过了什么,所有文档都以在mojolicious应用程序中使用"使用MongoDB;"开始,所以不知道该怎么做。

希望有人能指出我错过了什么。

安装模块:

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了

最新更新