Install MongoDB Community on Windows using the Zip File
Install MongoDB Community Edition
Download the MongoDB .zip file from the following link:
MongoDB Download Center.
You can create a configuration file to specify options for MongoDB. To do so, create a file named mongod.cfg in the \bin\ directory within the directory where you extracted the MongoDB files (< install directory>\bin\mongod.cfg). For more information on creating a config file, see
systemLog:
destination: file
path: "D:\\doc\\it\\mo\\bin\\mongod.log"
logAppend: true
storage:
dbPath: "D:\\doc\\it\\mo\\db"
net:
bindIp: localhost
port: 27017
Open a Windows command prompt/interpreter (cmd.exe) as an Administrator.
mongod.exe --dbpath="D:\doc\it\mo\db"
The --dbpath option points to your database directory.
To start MongoDB, run
mongod.exe --config "D:\doc\it\mo\bin\mongod.cfg" --install
Install mongosh
Download the mongosh .zip file from the following link:
MongoDB Download Center.
To confirm that mongosh installed successfully, open a command prompt and run the following command:
mongosh --version
To connect to a MongoDB deployment running on localhost with default port 27017, run mongosh without any options:
mongosh
Create a MongoDB database using the CLI
Use the show command to see all databases accessible in the cluster:
mongosh> show dbs
admin 40.00 KiB
config 72.00 KiB
local 112.00 KiB
mongosh>
Please note, admin and local are databases belonging to each MongoDB cluster.
To create a database, you first need to switch the context to a non-existent database using the use command:
mongosh> use com
switched to db com
com>
Add a document to the database
com> db.user.insertOne({nickname: "京京学堂", age:18})
{
acknowledged: true,
insertedId: ObjectId('6aae91df9d2d04f924abc115')
}
com>
To find the current database, type the db command:
com> db
com
com>