Skip to content

Commit

Permalink
feat: delete one local database user, #17
Browse files Browse the repository at this point in the history
  • Loading branch information
weaponsforge committed Apr 7, 2024
1 parent af72d0b commit 74da17d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions main.bat
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ GoTo Main
set /A PreviousScreen=0
set /A NextScreen=0

:: Local temporary files
set "LOG_FILE=log.txt"
set "TEMP_USERS_FILE=_users.txt"
set "LOCAL_USERS_FILE=users.txt"
set ENV_FILE=%cd%\.env
Expand Down Expand Up @@ -414,6 +416,34 @@ EXIT /B 0
EXIT /B 0


:: Deletes a local database user from a local database
:DeleteLocalDatabaseUser
cls
echo ----------------------------------------------------------
echo DELETE A LOCAL DATABASE USER
echo ----------------------------------------------------------
set "databaseName="
set "databaseUser="

set /p databaseName="Enter the database name:"
set /p databaseUser="Enter the database user:"
echo.

%MONGO_SHELL% %databaseName% --eval "db.dropUser('%databaseUser%')" > %LOG_FILE%

findstr /C:"ok:" %LOG_FILE% > nul

if %errorlevel% equ 0 (
echo Success! User [%databaseUser%] deleted.
) else (
echo Error deleting user
)

set /p go=Press enter to continue...
GoTo ViewDatabaseCredentials
EXIT /B 0


:: Deletes all database users of a given local database
:DeleteLocalDatabaseUsers
setlocal enabledelayedexpansion
Expand Down Expand Up @@ -742,4 +772,8 @@ EXIT /B 0
if exist %TEMP_USERS_FILE% (
del /f %TEMP_USERS_FILE%
)

if exist %LOG_FILE% (
del /f %LOG_FILE%
)
EXIT /B 0

0 comments on commit 74da17d

Please sign in to comment.