Skip to content

Commit c1a08c8

Browse files
author
Steven Surowiec
committed
Added search by id
1 parent ef2627f commit c1a08c8

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

mongodbadmin.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
167167

168168
$collection = $mongo->selectDB($db)->selectCollection($collection);
169169

170-
if (isset($_REQUEST['custom_id']) && !$forceCustomId) {
170+
if (isset($_REQUEST['custom_id']) || $forceCustomId) {
171171
$document =$collection->findOne(array('_id' => $id));
172172
} else {
173173
$document = $collection->findOne(array('_id' => new MongoId($id)));
@@ -178,6 +178,27 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
178178

179179
// Actions
180180
try {
181+
// SEARCH
182+
if (isset($_REQUEST['search'])) {
183+
$customId = false;
184+
$document = findMongoDbDocument($_REQUEST['search'], $_REQUEST['db'], $_REQUEST['collection']);
185+
186+
if (!$document) {
187+
$document = findMongoDbDocument($_REQUEST['search'], $_REQUEST['db'], $_REQUEST['collection'], true);
188+
$customId = true;
189+
}
190+
191+
if (isset($document['_id'])) {
192+
$url = $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
193+
194+
if ($customId) {
195+
header('location: ' . $url . '&custom_id=true');
196+
} else {
197+
header('location: ' . $url);
198+
}
199+
}
200+
}
201+
181202
// DELETE DB
182203
if (isset($_REQUEST['delete_db'])) {
183204
$mongo
@@ -345,6 +366,18 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
345366
padding: 8px;
346367
margin-bottom: 15px;
347368
width: 350px;
369+
float: left;
370+
}
371+
#search {
372+
-moz-border-radius: 10px;
373+
-webkit-border-radius: 10px;
374+
border-radius: 10px;
375+
background: #f5f5f5;
376+
border: 1px solid #ccc;
377+
padding: 8px;
378+
margin-bottom: 15px;
379+
width: 350px;
380+
float: right;
348381
}
349382
table {
350383
background: #333;
@@ -508,6 +541,14 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
508541
</div>
509542
<?php endif; ?>
510543

544+
<div id="search">
545+
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>&collection=<?php echo $_REQUEST['collection'] ?>" method="POST">
546+
<label for="search_input">Search by ID</label>
547+
<input type="text" id="search_input" name="search" size="20" />
548+
<input type="submit" name="submit_search" value="Search" />
549+
</form>
550+
</div>
551+
511552
<table>
512553
<thead>
513554
<th colspan="3">ID</th>

0 commit comments

Comments
 (0)