我已经通过composer安装了mongodb php库,但是我遇到了一个与权限有关的问题。有没有办法看看它是否正在运行(我认为它是,因为我显然有一个开放的连接),如果是这样,我将如何为此启用权限?
以下是代码:
$client = new \MongoDB\Client("mongodb://localhost:27017");
$collection = $client->test->foo;
$result = $collection->insertOne(['name' => 'foo', 'sex' => 'Male']);
$find = $collection->find(['name' => 'foo']);
foreach ($find as $entry) {
echo $entry['_id'] . ' : ' . $entry['name'] . ' : ' . $entry['sex'];
}
我收到的异常消息是:
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers
found (`serverselectiontryonce` set):
[Failed connecting to 'localhost:27017': Permission denied]
谢谢!
如果有人需要更多信息,请告诉我。
更新
我在系统shell上运行了命令mongo,这就是出现的结果:
MongoDB shell version: 2.6.11
connecting to: test
2016-06-15T06:59:58.752-0400 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-06-15T06:59:58.753-0400 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection failed at src/mongo/shell/mongo.js:146
exception: connect failed
答案 0 :(得分:0)
我有这个错误。 我不得不重新启动mongodb来完成这项工作。
我使用了以下命令
// REGULAR FUNCTION
function editTemplates() {
console.log(this) // window
var myVar = this;
// sits within for loop
clocksTemplate.gmt[i].addEventListener('keydown', function(e) {
// new value assigned for 'this' as element bound to clocksTemplate.gmt
console.log(this); // returns element bound to clocksTemplate.gmt
console.log(myVar); // returns window
});
// ARROW FUNCTION (Anonymous Functions)
function editTemplates() {
console.log(this) // returns window object
var myVar = this;
// sits within for loop
clocksTemplate.gmt[i].addEventListener('keydown', (e) => {
// No new value gets assigned to 'this'
console.log(this); // returns window object
console.log(myVar); // returns window object
// Saves the hassle of saving 'this' to another variable!
});