#!/bin/bash # Define colors for readable output GREEN="\033[0;32m" RED="\033[0;31m" YELLOW="\033[0;33m" BLUE="\033[0;34m" NC="\033[0m" # No Color echo -e "${BLUE}===== MongoDB Setup Script =====${NC}" echo -e "This script will help set up MongoDB for development with the Semblance app" # Check if MongoDB is running if ! pgrep -x "mongod" > /dev/null; then echo -e "${YELLOW}MongoDB is not running. Attempting to start MongoDB...${NC}" if [[ "$OSTYPE" == "darwin"* ]]; then # macOS brew services start mongodb-community || mongod --config /usr/local/etc/mongod.conf --fork else # Linux sudo systemctl start mongod || sudo service mongod start fi # Wait for MongoDB to start sleep 3 # Check again if ! pgrep -x "mongod" > /dev/null; then echo -e "${RED}Failed to start MongoDB. Please start it manually before running this script.${NC}" exit 1 else echo -e "${GREEN}MongoDB started successfully.${NC}" fi else echo -e "${GREEN}MongoDB is already running.${NC}" fi echo -e "${YELLOW}Setting up MongoDB for development (no authentication)...${NC}" # Connect to MongoDB and disable authentication if enabled mongo admin --eval 'db.disableAuth = function() { db.getSiblingDB("admin").system.users.remove({}); db.getSiblingDB("admin").system.version.remove({ "_id": "authSchema" }); db.getSiblingDB("admin").system.version.insert({ "_id": "authSchema", "currentVersion": 3 }); print("Authentication has been disabled. Please restart MongoDB for changes to take effect."); }; try { db.disableAuth(); } catch (e) { print("Error disabling auth: " + e); }' echo -e "${YELLOW}Creating semblance_db database and collections...${NC}" # Create database and collections mongo --eval 'db = db.getSiblingDB("semblance_db"); db.createCollection("users"); db.createCollection("personas"); db.createCollection("focus_groups");' echo -e "${GREEN}MongoDB setup completed. The database is now ready for development.${NC}" echo -e "${YELLOW}Note: You may need to restart MongoDB for all changes to take effect:${NC}" echo -e " - On macOS: brew services restart mongodb-community" echo -e " - On Linux: sudo systemctl restart mongod"