Closed ameyagh closed 3 years ago
Can you also post the script to migrate db here?
Can you also post the script to migrate db here?
import pymongo from pymongo import MongoClient
client = MongoClient() db = client['broadway_on_demand']
_ID = 'test-course'
courses = list(db.courses.find({'staff_ids': {'$exists': True}}))
def find_course(_ID, courses): for course in courses: if course['_id'] == _ID: return course
return None
course = find_course(_ID, courses)
admin_ids = course['admin_ids'] staff_ids = course['staff_ids']
staff = {'staff': {}}
for staff_id in staff_ids: staff['staff'][staff_id] = {'is_admin': False}
for admin_id in admin_ids: staff['staff'][admin_id] = {'is_admin': True}
try:
db.courses.update_one({'_id': _ID}, {'$set': staff})
# get rid of the staff_ids list
db.courses.update_one({'_id': _ID}, {'$unset': {'staff_ids': 1}})
# get rid of the admin_ids list
db.courses.update_one({'_id': _ID}, {'$unset': {'admin_ids': 1}})
print('Merged admin_ids and staff_ids')
except: print('Something when wrong')
Changed db.py code to be able to access database for the new schema. Merged admin_ids and staff_ids.