php mongodb :调用 db.php 中未定义的方法 MongoDB::insert()
我正在运行这段代码:
$db = new Mongo("mongodb://user:[email protected]: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
有什么问题?谢谢。
I'm running this code:
$db = new Mongo("mongodb://user:[email protected]:27081/dbname");
$collection = $db->foobar;
$collection->insert($content);
I'm trying to test mongohq by just creating a random collection.
I'm getting this error:
Fatal error: Call to undefined method MongoDB::insert() in /ajax/db.php on line 24
I have the client installed as far as I know:
I'm also running php 5.2.6
What's the problem? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个数据库包含一个或多个集合。您正在尝试插入数据库,而不是集合。
我没有使用过该扩展,但根据文档,该方法在 MongoDB 类中不存在。相反,它是
MongoCollection::insert
。您可以通过以下方式获取集合:(注释行相当于它下面的行。)
我猜您正在做类似的事情:(
编辑:我第一次没有看到您的代码片段。这正是)
我建议您阅读教程以获取更多信息。
Each DB contains one or many collections. You are trying to insert into the DB, instead of the collection.
I've not used that extension, but that method doesn't exist in the
MongoDB
class according to the documentation. Instead, it isMongoCollection::insert
. You get at a collection by:(The commented line is equivalent to the line below it.)
I'm guessing that you are doing something like:
(Edit: I didn't see your code snippet the first time. That is precisely what you are doing.)
I suggest that you read the tutorial for more information.