0
我是mLab的新手,試圖將相同的簡單文檔插入mLab上的mongodb。首先,我是能夠插入一些文件,通過使用Shell(命令行)任何時候我運行代碼的數據庫中,我得到這個錯誤:PHP插入文件mLab
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException:
No suitable servers found (`serverSelectionTryOnce` set): [connection timeout calling ismaster on 'ds157390.mlab.com:57390'] in C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php:726
Stack trace: #0 C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php(726): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 C:\xampp\htdocs\MongoDB\azureConnect.php(46): MongoDB\Collection->insertMany(Array) #2 {main} thrown in C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php on line 726
PHP-代碼:
<?php
ini_set('max_execution_time', 0);
require 'vendor/autoload.php';
$seedData = array(
array(
'decade' => '1970s',
'artist' => 'Debby Boone',
'song' => 'You Light Up My Life',
'weeksAtOne' => 10
),
array(
'decade' => '1980s',
'artist' => 'Olivia Newton-John',
'song' => 'Physical',
'weeksAtOne' => 10
),
array(
'decade' => '1990s',
'artist' => 'Mariah Carey',
'song' => 'One Sweet Day',
'weeksAtOne' => 16
),
);
$uname = "test";
$pword = "test";
$uri = "mongodb://".$uname.":".$pword."@ds157390.mlab.com:57390/data4estate";
$conn = new MongoDB\Client($uri);
$songs = $conn->data4estate->songs;
$songs->insertMany($seedData);
我已經試過了,但它仍然沒有工作 –