加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php mongodb:在db.php中调用未定义的方法MongoDB :: insert()

发布时间:2020-12-13 13:30:38 所属栏目:PHP教程 来源:网络整理
导读:我正在运行此代码: $db = new Mongo("mongodb://user:pw@flame.mongohq.com:27081/dbname"); $collection = $db-foobar; $collection-insert($content); 我试图通过创建一个随机集合来测试mongohq. 我收到这个错误: Fatal error: Call to undefined method
我正在运行此代码:
$db = new Mongo("mongodb://user:pw@flame.mongohq.com:27081/dbname");
    $collection = $db->foobar;

    $collection->insert($content);

我试图通过创建一个随机集合来测试mongohq.

我收到这个错误:

Fatal error:  Call to undefined method MongoDB::insert() in /ajax/db.php on line 24

据我所知,我安装了客户端:

我也在运行php 5.2.6

有什么问题?谢谢.

每个DB包含一个或多个集合.您正在尝试插入数据库,而不是集合.

我没有使用该扩展,但根据文档,MongoDB类中不存在该方法.相反,它是MongoCollection :: insert.你得到一个集合:

// $collection = $mongo->selectDB("foo")->selectCollection("bar");
$collection = $mongo->foo->bar; 
$collection->insert(array('x' => 1));

(注释行等同于它下面的行.)

我猜你做的是:

$collection = $mongo->foo;
$collection->insert(array('x' => 1));

(编辑:我没有第一次看到你的代码片段.这正是你正在做的事情.)

我建议您阅读tutorial了解更多信息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读