Skip to content

Commit

Permalink
Transfer Database (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
avgupta456 authored Jan 13, 2024
1 parent 3ace8a7 commit c9f5ac2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/scripts/delete_old_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def delete_old_rows(cutoff_date: datetime):

async def main():
# Replace 'your_date_field' with the actual name of your date field
cutoff_date = datetime(2022, 12, 31)
cutoff_date = datetime(2023, 12, 31)

count = await count_old_rows(cutoff_date)
if count == 0:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/data/mongo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def get_conn_str(password: str, database: str) -> str:
return f"mongodb+srv://root:{password}@backend.aqlpb.mongodb.net/{database}?retryWrites=true&w=majority"
return f"mongodb+srv://root:{password}@backend2.e50j8dp.mongodb.net/{database}?retryWrites=true&w=majority"


if LOCAL:
Expand Down
31 changes: 31 additions & 0 deletions backend/transfer_mongodb.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if [ $# -eq 0 ]; then
echo "Usage: $0 <mongodb_password>"
exit 1
fi

# Export
mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db dev_backend --collection secrets --username root --password "$1" > ./dev_secrets.json
mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db dev_backend --collection users --username root --password "$1" > ./dev_users.json
mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db dev_backend --collection user_months --username root --password "$1" > ./dev_user_months.json

mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db prod_backend --collection secrets --username root --password "$1" > ./prod_secrets.json
mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db prod_backend --collection users --username root --password "$1" > ./prod_users.json
mongoexport --uri "mongodb+srv://backend.aqlpb.mongodb.net/" --db prod_backend --collection user_months --username root --password "$1" > ./prod_user_months.json

# Import
mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db dev_backend --collection secrets --username root --password "$1" < ./dev_secrets.json
mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db dev_backend --collection users --username root --password "$1" < ./dev_users.json
mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db dev_backend --collection user_months --username root --password "$1" < ./dev_user_months.json

mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db prod_backend --collection secrets --username root --password "$1" < ./prod_secrets.json
mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db prod_backend --collection users --username root --password "$1" < ./prod_users.json
mongoimport --uri "mongodb+srv://backend2.e50j8dp.mongodb.net/" --db prod_backend --collection user_months --username root --password "$1" < ./prod_user_months.json

# Remove
rm ./dev_secrets.json
rm ./dev_users.json
rm ./dev_user_months.json

rm ./prod_secrets.json
rm ./prod_users.json
rm ./prod_user_months.json

1 comment on commit c9f5ac2

@vercel
Copy link

@vercel vercel bot commented on c9f5ac2 Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.