Skip to main content

How to setup MongoDB on Windows?



Download the current MongoDB windows installation .msi file from https://www.mongodb.org/downloads  matching your requirement.


Run the file and carry out the installation process. It is easy. You will be guided through the installation process.

PS: The 3.2 and 3.0 releases of MongoDB does not work in windows. But the older releases does. In my case, I installed MongoDB 2.6 Standard version.

Now open the command prompt and go to the bin folder of the MongoDB installation. In my case, it is C:\Program Files\MongoDB 2.6 Standard\bin

Run the mongod.exe file there by typing the command
                                                                      mongod
You will find an error saying \data\db does not exists as shown in the figure below, and the .exe stops.


Then go to the directory where MongoDB is installed and create a folder structure named data/db. But you can create it where ever you like. In my case it is as above.

Then run the following command in the command prompt.
mongod --dbpath="C:\Program Files\MongoDB 2.6 Standard\data"

You will see the following.


The server will be waiting for connections on port 27017 which is the default port for MongoDB.

To test the installation, keep this command prompt as it is, and open a new command prompt and type the command
mongo.exe

         while in the same bin directory above. You will see the following output.


PS: See there are 2 command prompts in the above figure.

MongoDB gets created with a test database called "test". We can verify the correctness of our installation by issuing a query to this test database.

Type in the following commands.

> db.test.save({TharikasTestField:'My name is Tharika!'})

This query will insert a record to the test database, "test" is the name of the database. save() is to insert a record. Then you give the field and the value in curly brackets separated by a colon.

> db.test.find()

This command will printout the inserted record as shown in the following figure.


So you can see that we have successfully setup MongoDB on windows. Cheers! :)

Comments

Popular posts from this blog

How to connect my database instance with elastic beanstalk instance in AWS?

If you have deployed your web application in Elastic Beanstalk in AWS and now you need to connect a database to this instance, and your database is actually residing in a different instance, how can you actually connect them? It's easy with Elastic Beanstalk. I will explain an example scenario that I used for connecting my elastic beanstalk web application with another instance containing my MongoDB database. By looking at this, you can customize as per your need. Don't worry. This is easy. :) The only things you need here are the details about the 1. Database name that you need to connect to. Ex:- "myDB" 2. Port at which the database instance is listening. EX:- In the case of MongoDB, the listening port is 27017 3. Host name of your database instance. EX:- Like localhost, in this case, it will be the Public DNS of your database instance 4. The password of your database if exists. First these details need to be set as environment variables in Elastic Be

How to import the Public Certificate of one WSO2 product to the trust store of another?

To demonstrate this point, I will use the 2 products WSO2 API Manager 2.1.0 (referred as APIM from here onwards) and WSO2 Enterprise Integrator 6.1.1 (referred as EI from here onwards). When using EI as the Business Process Server during configuration of Workflows in APIM, one step to perform is to import the public certificate of EI to the truststore of APIM [1]. So now let's see how this can be done. Step 1: Go to <EI_HOME>/repository/resources/security/ folder and execute the following keytool command. This command is used to export the public certificate of EI as a certificate file called wso2carbon.cer. Since the default keystore in EI is wso2carbon.jks, we have specified it as the keystore and the default alias is wso2carbon. Provide wso2carbon as the keystore password when prompted as it is the default password. After executing the above command from within the security folder in EI, you will see that a file with the name of wso2carbon.cer is created