php


PHP insert document mLab


I'm new at mLab and trying to insert same simple documents to my mongodb on mLab. First of all I was able to insert some documents to the database using the shell (command line) anytime I run the code I get this error:
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-Code:
<?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);
Try to follow instruction for connection timout:
https://blog.mlab.com/2013/10/do-you-want-a-timeout/
Try to set timeout option to connection string
https://docs.mongodb.com/manual/reference/connection-string/#uri.connectTimeoutMS
$uri = "mongodb://".$uname.":".$pword."#ds157390.mlab.com:57390/data4estate?connectTimeoutMS=300000";
You can set the socketTimeoutMS on php MongoClient as answered here:
PHP MongoDb driver: How to set timeout for executing a code

Related Links

how to insert data with where cause
$_SERVER['PATH_INFO] variable failing due to mod_rewrite
check if a city is in a country with northeast lat/lng and southwest lat/lng
Sql select max id from table
remember user checked boxes populated from db
How to stop symfony2 to create session cookie or how can i encrypt session in config.yml?
Infinite scrolling repeats… I have no idea why
Make dir with php and html form
php url with comma changes into ASCII code
Jquery query string keeping variables
Laravel migration creates migration table instead of users as expected
How to check if an array contains another array in PHP?
How to insert multiple MySQL table rows from a PHP array
Check if a class has been instantiated
Difference between object creation using `new ClassName` and `new ClassName()` in PHP
How to add attributes option to XML

Categories

HOME
entity-framework
android-studio
plesk
dotnetnuke
barcode-scanner
systemd
message-queue
code-formatting
biztalk
google-play-services
twitter-fabric
bittorrent
native-base
mutation-testing
phpstorm-2017.1
graphdb
mpu6050
l20n
coroutine
spam
akka-persistence
sharedpreferences
qa
exchange-server-2010
animated-gif
pyopencl
msdeploy
onchange
macromedia
spring-annotations
tsung
monitor
premake
private-key
custom-keyboard
bootstrap-sass
char-pointer
jslint
telephonymanager
llvm-ir
sspi
sbjson
grunt-contrib-watch
oauth2-playground
doctrine-extensions
jshint
beeline
renderman
redisson
iptv
datediff
winmerge
scala-collections
deedle
patternlab.io
mobile-angular-ui
gmaps.js
.when
hmmlearn
pjax
livecycle
wolfram-language
highlighting
preferenceactivity
flush
odesk
gdl
android-handler
unidata
erlog
sablecc
fiware-bosun
directorysearcher
comctl32
wicket-1.5
cout
xml-signature
iplimage
distributed-r
windows-messages
commenting
rails-api
thruway
meteorite
frontbase
django-facebook
aero
oscilloscope
jbox2d
background-thread
proc-open
xalan
instance-variables
voice-recording
jzmq
autosize
affinetransform
nsconnection
aptitude
.net-services
source-code-protection
tacit-programming
xap

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App