【问题标题】:Mojolicious + MongoDB: Can't locate MongoDB.pm errorMojolicious + MongoDB:找不到 MongoDB.pm 错误
【发布时间】:2015-03-11 20:34:31
【问题描述】:

我的应用程序在每次包含“使用 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 应用程序中,所以不知道该怎么做。

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

【问题讨论】:

  • 你安装了模块吗?可能不是你可能对Mogolicious::Plugin::Mongodb 更感兴趣,考虑到你的堆栈选择。这次记得实际从 CPAN 安装。
  • @Neil Lunn 谢谢。我已经从 cpan.org 下载了“Mojolicious-Plugin-Mongodb-1.16”。你能告诉我在我的 mojolicious 项目中我必须将它存储在哪里,或者我可以在哪里更好地记录自己。
  • 太宽泛了。 CPAN 安装要么是“全局的”,要么是本地化的,具体取决于 perlbrewplenv 甚至 local::lib 之类的使用。不是想居高临下,但您的“下载”评论并不能让人相信您确实正确地完成了这些事情。
  • 感谢 cmets @ Neil Lunn

标签: perl mongodb mojolicious-lite


【解决方案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

【讨论】:

    猜你喜欢
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多