Skip to content

Commit 967c835

Browse files
committed
2 parents b5c8401 + 8b2ee03 commit 967c835

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

mongodbadmin.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,12 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
533533
$skip = ($page - 1) * $max;
534534

535535
if (isset($_REQUEST['search']) && is_object(json_decode($_REQUEST['search']))) {
536+
$search = json_decode($_REQUEST['search'], true);
537+
536538
$cursor = $mongo
537539
->selectDB($_REQUEST['db'])
538540
->selectCollection($_REQUEST['collection'])
539-
->find(json_decode($_REQUEST['search'], true))
541+
->find($search)
540542
->limit($limit)
541543
->skip($skip);
542544
} else {
@@ -583,8 +585,34 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
583585
<td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&id=<?php echo (string) $document['_id'] ?>&custom_id=1"><?php echo (string) $document['_id'] ?></a></td>
584586
<?php endif; ?>
585587
<td>
586-
<?php $values = array_values($document) ?>
587-
<?php echo isset($values[1]) ? $values[1] : '-' ?>
588+
<?php
589+
if (isset($search)) {
590+
$displayValues = array();
591+
592+
$searchKeys = isset($search['$query']) ? $search['$query'] : $search;
593+
594+
foreach ($searchKeys as $fieldName => $searchQuery) {
595+
if ($fieldName != '_id' && $fieldName[0] != '$' && isset($document[$fieldName])) {
596+
$fieldValue = $document[$fieldName];
597+
598+
if (!is_array($fieldValue) && !is_object($fieldValue)) {
599+
$displayValues[] = $fieldName . ': ' . substr(str_replace("\n", '', htmlspecialchars($fieldValue)), 0, 100);
600+
}
601+
}
602+
}
603+
604+
echo implode(' - ', $displayValues);
605+
}
606+
607+
if (!isset($displayValues) || !count($displayValues)) {
608+
foreach ($document as $fieldName => $fieldValue) {
609+
if ($fieldName != '_id' && !is_array($fieldValue) && !is_object($fieldValue)) {
610+
echo $fieldName . ': ' . substr(str_replace("\n", '', htmlspecialchars($fieldValue)), 0, 100);
611+
break;
612+
}
613+
}
614+
}
615+
?>
588616
</td>
589617
<?php if (is_object($document['_id']) && $document['_id'] instanceof MongoId): ?>
590618
<td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a></td>

0 commit comments

Comments
 (0)