Skip to content

Commit

Permalink
Merge pull request #979 from pjcdawkins/mongo-fixes
Browse files Browse the repository at this point in the history
Misc MongoDB fixes for multi-instance setups
  • Loading branch information
pjcdawkins authored Sep 1, 2020
2 parents 8d9a678 + fb24673 commit cf03637
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Command/Service/MongoDB/MongoExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Service/Relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down

0 comments on commit cf03637

Please sign in to comment.