I am trying to import a CSV to server's mongoDB by php. I already done the update file part and now I can get the CSV file that client update to the server. so now I am trying to import CSV file to mongoDB by using shell_exec() , here is my PHP code.
$importCommand = 'mongoimport -d test -c test --type csv --file yourfile.csv --headerline';
$output = shell_exec($importCommand.' 2>&1');
echo $output;
when I run this part of code in terminal by php -f it works(I know my CSV is not there so no import has been made),
$ mongoimport -d test -c test --type csv --file yourfile.csv --headerline
2017-03-22T13:46:22.668+0800 Failed: open yourfile.csv: no such file or directory
2017-03-22T13:46:22.668+0800 imported 0 documents"
as can be seen this works perfectly fine. The 'mongoimport' can be found and work fine. However when I add this to my php that use to update the file the output become
sh: mongoimport: command not found
Any idea how to solve this problem? Thanks for your time.