-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_mongo_db_indices.py
24 lines (22 loc) · 1.17 KB
/
check_mongo_db_indices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from server.storage import nosql_db as sandbox_db
from server.storage.local.mongo_db import MongoDB
devportal_db = MongoDB(
host="mongodb+srv://nlm:[email protected]",
db="doc-store-dev",
)
sandbox_collections = sandbox_db.db.list_collection_names()
for col in sandbox_collections:
print(f"Checking index information for {col}")
sandbox_index_info = sandbox_db.db[col].index_information()
dev_portal_index_info = devportal_db.db[col].index_information()
if bool(sandbox_index_info.keys() - dev_portal_index_info.keys()) or bool(
dev_portal_index_info.keys() - sandbox_index_info.keys(),
):
print(f"Indices different for {col}")
for dev_index_key in dev_portal_index_info.keys():
if dev_index_key not in sandbox_index_info.keys():
print(f"{dev_index_key} not present in sandbox {col}")
missing_index_list = dev_portal_index_info[dev_index_key]["key"]
new_list = [(x, int(y)) for x, y in missing_index_list]
print(f"Creating index {dev_index_key} in {col} with values {new_list}")
sandbox_db.db[col].create_index(new_list)