@@ -167,7 +167,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
167
167
168
168
$ collection = $ mongo ->selectDB ($ db )->selectCollection ($ collection );
169
169
170
- if (isset ($ _REQUEST ['custom_id ' ]) && ! $ forceCustomId ) {
170
+ if (isset ($ _REQUEST ['custom_id ' ]) || $ forceCustomId ) {
171
171
$ document =$ collection ->findOne (array ('_id ' => $ id ));
172
172
} else {
173
173
$ document = $ collection ->findOne (array ('_id ' => new MongoId ($ id )));
@@ -178,6 +178,27 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
178
178
179
179
// Actions
180
180
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
+
181
202
// DELETE DB
182
203
if (isset ($ _REQUEST ['delete_db ' ])) {
183
204
$ mongo
@@ -345,6 +366,18 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
345
366
padding: 8px;
346
367
margin-bottom: 15px;
347
368
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;
348
381
}
349
382
table {
350
383
background: #333;
@@ -508,6 +541,14 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
508
541
</div>
509
542
<?php endif ; ?>
510
543
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
+
511
552
<table>
512
553
<thead>
513
554
<th colspan="3">ID</th>
0 commit comments