This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
How To Setup Local MongoDB
DerekRuiz edited this page Nov 16, 2021
·
3 revisions
- Go to the site: https://www.mongodb.com/try/download/community
- Download the community server version
- Open File Explorer
- Navigate to the folder that the MongoDB was downloaded:
for example "C:\Program Files\MongoDB\Server\5.0\bin"
- Open a command prompt (open in administration mode if MongoDB is in "C:\Program Files")
- Change directory to the folder that the MongoDB was downloaded:
for example cd "C:\Program Files\MongoDB\Server\5.0\bin"
- Open task manager
- Go to the processes tab
- Find the processes called "MongoDB Database Server"
- Click on the process and End Task
- In the command prompt enter the following command
mongod.exe --replSet rs0 --dbpath="C:\Program Files\MongoDB\Server\5.0\data"
(the --dbpath flag is optional, this is where the database files will be saved) - Keep this command prompt running in the background
- Using File Explorer, open the application called: "mongo.exe"
- A new command window should open
- type the following command:
rs.initiate()
- A message should output stating "ok": 1, and the command should start with "rs0: Primary>"
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "tutorialkart:27017",
"ok" : 1
}
rs0: Primary > |
Now MongoDB is running locally using replica sets.
- To use replica sets in the future, you only need to run the command:
mongod.exe --replSet rs0 --dbpath="C:\Program Files\MongoDB\Server\5.0\data"
(the --dbpath flag is optional, this is where the database files will be saved)
- Create a .bat file in the bin folder and enter the line:
mongod.exe --replSet rs0 --dbpath="C:\Program Files\MongoDB\Server\5.0\data"
- Save the .bat file.
- To run a MongoDB instance, just run that .bat file