为什么MongoDB类在Laravel中不起作用? [英] Why MongoDB Class doesn't work in Laravel?

查看:55
本文介绍了为什么MongoDB类在Laravel中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Laravel中使用MongoDB,这是我在Controller中的代码:

I want to use MongoDB in Laravel, This is my code in Controller :

public function create (Request $request) {
    $m = new MongoClient();
    $db = $m->selectDB("Laravel");      
    $collection = $db->selectCollection("Posts");
    $document = array( 
       "Title" => $request->input('Title'), 
       "Publisher" => $request->input('Publisher')
    );      
    $collection->insert($document);
}    

但是当我单击提交"时,它给我一个错误:

But when I click "Submit", It gives me an error :

致命错误:找不到类'App \ Http \ Controllers \ MongoClient'

Fatal error: Class 'App\Http\Controllers\MongoClient' not found

我已经运行过MongoDB Server&还有Wamp&我已经安装了MongoDB&它是PHP的驱动程序...

I have run MongoDB Server & also Wamp & I have Installed MongoDB & It's Driver for PHP ...

我的错误是什么? (我应该说,我还没有通过使用MongoDB进行Laravel的任何配置,是否需要?)

What is My Mistake ? (I should say that I haven't done any config for Laravel by using MongoDB, Is it needed ?)

推荐答案

Laravel没有MongoDB的驱动程序.

Laravel doesn't come with a driver for MongoDB.

如果要在laravel中使用mongo,则必须创建自己的类来处理它或使用该类:

If you want to use mongo with laravel you'll have to create your own class to deal with it or use this one:

laravel-mongodb

这篇关于为什么MongoDB类在Laravel中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆