You may also like to read:

Introduction

Here we will find installing zip version of MongoDB in Windows environment. We will install here MongoDB Community edition. If you want to install MongoDB MSI version then you can read Step 4 at https://www.roytuts.com/mongodb-php7-xampp-windows/. We will download latest(as of today) MongoDB server and configure in Windows environment.

Downloading MongoDB

Download MongoDB server community edition from MongoDB Download Center.

Choose the ZIP version of your package and choose your Operating version similar to the below image:

installing zip version of MongoDB in windows

Here I have chosen Windows 64-bit, you can choose as per your Operating System version.

You must select the Package as ZIP.

Now click on Download button and save into an appropriate location on your computer’s disk.

Installing MongoDB

Now extract the zip file into a drive, for example, C:\. You can also extract in any location as per your choice or requirements.

Creating Directory – data\db

Now create a directory called data\db in parallel to the root directory of the MongoDB extracted folder.

The data\db directory is required to save the database records.

Note if you do not create such directory then you will get below error in the console output:

exception in initAndListen: NonExistentPath: Data directory <disk drive of mongodb installation root directory>:\data\db\ not found., terminating

Running the MongoDB Server

No we will run our MongoDB server by executing the following command from cmd window.

Navigate to the <MongoDB root directory>/bin folder in cmd window and execute the mongod.exe file.

For example,

C:\mongodb-4.0.10\bin>mongod.exe

Once your server starts successfully, you will see below output in the console:

10:46:47.482+0530 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
10:46:47.488+0530 I CONTROL  [initandlisten] MongoDB starting : pid=6200 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-KDLKCQ0
...
10:46:47.490+0530 I CONTROL  [initandlisten] db version v4.0.10
...
10:46:47.498+0530 I CONTROL  [initandlisten] allocator: tcmalloc
10:46:47.499+0530 I CONTROL  [initandlisten] modules: none
10:46:47.503+0530 I CONTROL  [initandlisten] build environment:
10:46:47.504+0530 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
10:46:47.505+0530 I CONTROL  [initandlisten]     distarch: x86_64
10:46:47.506+0530 I CONTROL  [initandlisten]     target_arch: x86_64
10:46:47.509+0530 I CONTROL  [initandlisten] options: {}
10:46:47.519+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3511M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
10:46:47.595+0530 I STORAGE  [initandlisten] WiredTiger message [1561785407:595475][6200:140734197224032], txn-recover: Set global recovery timestamp: 0
10:46:47.609+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
10:46:47.652+0530 I CONTROL  [initandlisten]
10:46:47.654+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
10:46:47.659+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
10:46:47.663+0530 I CONTROL  [initandlisten]
10:46:47.665+0530 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
10:46:47.668+0530 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
10:46:47.670+0530 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
10:46:47.674+0530 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
10:46:47.676+0530 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
10:46:47.678+0530 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
10:46:47.682+0530 I CONTROL  [initandlisten]
10:46:47.687+0530 I STORAGE  [initandlisten] createCollection: admin.system.version with provided UUID: 8e9cafd8-c2db-4484-a2ec-6a7663c36480
10:46:47.708+0530 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 4.0
10:46:47.718+0530 I STORAGE  [initandlisten] createCollection: local.startup_log with generated UUID: a9ca5103-84c3-40c0-afd0-8cf8d5900658
10:46:48.918+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
10:46:48.926+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
10:46:48.926+0530 I STORAGE  [LogicalSessionCacheRefresh] createCollection: config.system.sessions with generated UUID: cbc62e75-5739-4804-a014-4c16ead55721
10:46:48.967+0530 I INDEX    [LogicalSessionCacheRefresh] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }
10:46:48.967+0530 I INDEX    [LogicalSessionCacheRefresh]     building index using bulk method; build may temporarily use up to 500 megabytes of RAM
10:46:48.983+0530 I INDEX    [LogicalSessionCacheRefresh] build index done.  scanned 0 total records. 0 secs

Look for the below line in the above log so you know that your MongoDB server has been started successfully.

10:46:48.926+0530 I NETWORK  [initandlisten] waiting for connections on port 27017

Running MongoDB Client

We want to test whether our MongoDB server is running or not and perform some database operations. So run the mongo.exe file in the bin folder in cmd window.

For example,

C:\mongodb-4.0.10\bin>mongo.exe

Once your MongoDB client successfully connects to the mongoDB server, then you will find below output along with other output:

MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("6474b462-7253-4328-8ece-359da1ccb7e5") }
MongoDB server version: 4.0.10
Welcome to the MongoDB shell.

So a session will be established with your server for allowing client perform database operations.

Performing MongoDB Operations

I will show you few basic things here but you can always find more commands here.

The default database that comes with MongoDB is test.

We will perform all operations on MongoDB Client using the command.

Creating Database

Create a new database by using below command on the MongoDB Client terminal.

use roytuts

Checking Database

Now we will check what is our current database we are using for our application by using below command.

db

Creating Collection

We have created database, now we need to create collection, where our data will be stored.

Use below command to create a collection called user:

db.runCommand( { create: "user" });

Selecting Collections

You can select collections for your current database using below command:

db.getCollectionNames();

You can find below image to see what are all outputs for the above commands executed.

installing zip version of mongodb in windows

Removing Records From Collection

If you want to remove all records from a collection, then you can execute below command.

db.user.remove({})

Where user is the name of the collection.

If you want to remove a particular record, for example, you want to remove a user whose name is Soumitra, then you can use below command.

db.user.remove({"name":"Soumitra"})

Dropping Collection

To drop a collection from database you can execute below command.

db.user.drop()

Where user is the name of the collection.

That’s all. I hope you got an idea on installing zip version of MongoDB in Windows environment.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *