Skip to content

Commit 8b2ee03

Browse files
author
Steven Surowiec
committed
Updated sample data display to be more intelligent about what it displays
1 parent 1cde786 commit 8b2ee03

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
@@ -532,10 +532,12 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
532532
$skip = ($page - 1) * $max;
533533

534534
if (isset($_REQUEST['search']) && is_object(json_decode($_REQUEST['search']))) {
535+
$search = json_decode($_REQUEST['search'], true);
536+
535537
$cursor = $mongo
536538
->selectDB($_REQUEST['db'])
537539
->selectCollection($_REQUEST['collection'])
538-
->find(json_decode($_REQUEST['search'], true))
540+
->find($search)
539541
->limit($limit)
540542
->skip($skip);
541543
} else {
@@ -582,8 +584,34 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
582584
<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>
583585
<?php endif; ?>
584586
<td>
585-
<?php $values = array_values($document) ?>
586-
<?php echo isset($values[1]) ? $values[1] : '-' ?>
587+
<?php
588+
if (isset($search)) {
589+
$displayValues = array();
590+
591+
$searchKeys = isset($search['$query']) ? $search['$query'] : $search;
592+
593+
foreach ($searchKeys as $fieldName => $searchQuery) {
594+
if ($fieldName != '_id' && $fieldName[0] != '$' && isset($document[$fieldName])) {
595+
$fieldValue = $document[$fieldName];
596+
597+
if (!is_array($fieldValue) && !is_object($fieldValue)) {
598+
$displayValues[] = $fieldName . ': ' . substr(str_replace("\n", '', htmlspecialchars($fieldValue)), 0, 100);
599+
}
600+
}
601+
}
602+
603+
echo implode(' - ', $displayValues);
604+
}
605+
606+
if (!isset($displayValues) || !count($displayValues)) {
607+
foreach ($document as $fieldName => $fieldValue) {
608+
if ($fieldName != '_id' && !is_array($fieldValue) && !is_object($fieldValue)) {
609+
echo $fieldName . ': ' . substr(str_replace("\n", '', htmlspecialchars($fieldValue)), 0, 100);
610+
break;
611+
}
612+
}
613+
}
614+
?>
587615
</td>
588616
<?php if (is_object($document['_id']) && $document['_id'] instanceof MongoId): ?>
589617
<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)