11from mongoengine import Document , connect , get_db
22from pymongo import MongoClient
33from typing import Iterable , List , Optional
4- from pprint import pprint , List , Optional
5- import pprint
4+ from pprint import pprint
65import ast
76
87def _format_index (index : dict ) -> str :
@@ -14,7 +13,6 @@ def _format_index(index: dict) -> str:
1413 f' Keys: {{ { index_keys_formatted } }}'
1514 )
1615
17-
1816class MongoDBDatabase :
1917 """MongoEngine wrapper around a database."""
2018
@@ -67,6 +65,7 @@ def get_usable_collection_names(self) -> Iterable[str]:
6765 return sorted (self ._include_collections )
6866 return sorted (self ._all_collections - self ._ignore_collections )
6967
68+
7069 def get_usable_document_names (self , collection_name : str ) -> Iterable [str ]:
7170 """Get names of documents available in a given collection."""
7271 if collection_name not in self ._ignore_collections :
@@ -99,6 +98,7 @@ def get_collection_info(self, collection_name: str) -> str:
9998
10099 return f"Collection Information for '{ collection_name } ':\n { formatted_info } "
101100
101+
102102 def get_document_info (self , collection_names : Optional [List [str ]] = None ) -> str :
103103 """Get information about specified collections."""
104104 all_collection_names = self .get_usable_collection_names ()
@@ -156,8 +156,7 @@ def _execute(self, command: str) -> str:
156156 """Execute a command and return the result."""
157157 db = get_db ()
158158 result = db .command (ast .literal_eval (command ))
159- return f"Result:\n { result } "
160-
159+ return result
161160
162161 def run (self , command : str ) -> str :
163162 """Run a command and return a string representing the results."""
0 commit comments