diff --git a/src/Command/Service/MongoDB/MongoExportCommand.php b/src/Command/Service/MongoDB/MongoExportCommand.php index cfbf7ea49..d298f85f9 100644 --- a/src/Command/Service/MongoDB/MongoExportCommand.php +++ b/src/Command/Service/MongoDB/MongoExportCommand.php @@ -108,13 +108,21 @@ private function getCollections(array $service, HostInterface $host) $command = 'mongo ' . $relationshipsService->getDbCommandArgs('mongo', $service) - . ' --quiet --eval ' . OsUtil::escapePosixShellArg($js); + . ' --quiet --eval ' . OsUtil::escapePosixShellArg($js) + . ' 2>/dev/null'; $result = $host->runCommand($command); if (!is_string($result)) { return []; } + // Handle log messages that mongo prints to stdout. + // https://jira.mongodb.org/browse/SERVER-23810 + // Hopefully the end of the output is a JavaScript array. + if (substr($result, -1) === ']' && substr(trim($result), 0, 1) !== '[' && ($openPos = strrpos($result, "\n[")) !== false) { + $result = substr($result, $openPos); + } + $collections = json_decode($result, true) ?: []; return array_filter($collections, function ($collection) { diff --git a/src/Service/Relationships.php b/src/Service/Relationships.php index d761401dc..179ad58a8 100644 --- a/src/Service/Relationships.php +++ b/src/Service/Relationships.php @@ -274,6 +274,12 @@ public function getDbCommandArgs($command, array $database, $schema = null) case 'mongodump': case 'mongoexport': case 'mongorestore': + if (isset($database['url'])) { + if ($command === 'mongo') { + return $database['url']; + } + return sprintf('--uri %s', OsUtil::escapePosixShellArg($database['url'])); + } $args = sprintf( '--username %s --password %s --host %s --port %d', OsUtil::escapePosixShellArg($database['username']),