首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP + MongoHQ : MongoCursorException

PHP + MongoHQ : MongoCursorException
EN

Stack Overflow用户
提问于 2010-06-16 18:23:28
回答 1查看 2.2K关注 0票数 1

我正在尝试在PHP中使用mongodb。为此,我创建了一个MongoHQ实例,但是由于某些原因,当我试图从我的php服务器插入一些东西或任何其他操作时,我得到了以下错误:

代码语言:javascript
复制
Fatal error: Uncaught exception 'MongoCursorException' with message 'unauthorized for db [datab] lock type: -1 ' in C:\Program Files\EasyPHP5.3.0\www\application\controllers\Stat.ctrl.php:56 
Stack trace: 
  #0 C:\Program Files\EasyPHP5.3.0\www\application\controllers\Stat.ctrl.php(56): MongoCursor->rewind() 
  #1 C:\Program Files\EasyPHP5.3.0\www\index.php(105): Stat->index() 
  #2 {main} thrown in C:\Program Files\EasyPHP5.3.0\www\application\controllers\Stat.ctrl.php on line 56

有人知道它是从哪里来的吗?

这是我使用的php代码:

代码语言:javascript
复制
$username = 'test';
$password = 'test';

try
{
$link = new Mongo( "flame.mongohq.com:27022/datab -u <".$username."> -p <".$password.">" );

//MongoDB::authenticate ( $username , $password )
//$link = new Mongo();
}
catch(MongoConnectionException $e)
{
die('Could not connect. Check to make sure MongoDB is running.');
}
$db = $link->datab;
$col = $db->order;

try
{
// Insert a document (row) into the collection (table)
$doc = array('login' => 'jsmith', 'password' => ' 5f4dcc3b5aa765', 'email' => 'jsmith@example.com');
$col->insert($doc, true);

$doc = array('login' => 'psmith', 'password' => ' 5f4dcc3b', 'email' => 'psmith@example.com');
$col->insert($doc, true);
}
catch(MongoCursorException $e)
{
echo 'Je suis la!';
}

// Get the id of last insert
$id = $doc['_id'];

// Get all documents
$res = $col->find();

echo 'All documents:<br/>';

foreach($res as $doc)
{
echo '<pre>';
print_r($doc);
echo '</pre>';
}

// Query for the document matching the last insert ID
$doc = $col->findone(array('_id' => $id));

echo 'Single document (_id = $id):<br/><pre>';
print_r($doc);

// Update a document
$col->update(array('_id' => $id), array('$set' => array('password' => 'b497dd1a701a33033620780d')));

// Query the updated docuemnt
$doc = $col->findone(array('_id' => $id));

echo 'Updated docuement:<br/><pre>';
print_r($doc);
echo '</pre>';
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-17 04:33:02

这不是MongoDB使用的连接格式。参见http://www.php.net/manual/en/mongo.construct.php

您可能需要将其更改为类似以下内容:

代码语言:javascript
复制
$m = new Mongo("mongodb://$username:$password@flame.mongohq.com:27022/datab");
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3052403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档