Skip to main content

Installing Mongo database on Linux



I was trying to learn basics of using Mongo database recently. I am capturing some of the things I learnt below so it will be helpful for other people.

Installing Mongo database on Linux:

First lets intall Mongo db. I use a Ubuntu OS laptop. Below are steps to follow to install Mongo -
  • In Linux, it is better to use the package manager to install software. In Ubuntu, we can use the apt commands to install mongo
  • To ensure authenticity of the package that needs to be installed, Ubuntu requires packages be signed with GPG keys. As a first step, let us download the key from ubuntu.com.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 

 
  • Next we will need to add the repository for mongo in the list of sources for your ubuntu laptop. I will do that by creating a list file for mongo -
 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list


  • Next keep the ubuntu package database updated
 sudo apt-get update
  • now lets install mongo. Install the latest version always unless you have a specific reason to use an older version
 sudo apt-get install -y mongodb-org





  • Now this installs mongodb in your Ubuntu. To start Mongo services, in a terminal window, type - mongod . This will start mongo services with port 27017
  • To log into mongo shell and query the database, in another terminal type - mongo
Now, lets look at some useful commands to know while working with a mongo database -
  •  show dbs
this shows all available databases present
  • use <db name>
 this switches to the appropriate database you specified
  • show collections
this command shows all collections in the database
  • db.<collection>.find()
this command shows all documents within the collection you specified.

  • db.<collection>.insert({"test":"123"})
this command inserts a document into the collection with the json data i specified.
There are many more commands to learn -  db.<collection>.update, etc

At least hopefully this will get you started. Enjoy!

Comments

Popular posts from this blog

Workaround to bypass Salesforce SSO

One of the best practices for implementing Single Sign On for your Salesforce org is always ensure there is a way your System administrator can login via the standard login page side-stepping the SSO configuration.  Reason for this is if ever something goes wrong with your Idp provider's service and the SSO authentication responses are not coming as expected, all your users are unable to login. That is, if you have setup your My domain to prevent logins via standard Salesforce login urls (login.salesforce.com). This includes the System administrator as well. Only if your system administrator can somehow login, then he or she can disable the SSO settings for your domain and allow login via the normal login page as a temporary measure. What do you do in such a situation? Well Salesforce has built a workaround for this which is not well documented anywhere (probably for a good reason :) ). I found out about it from a colleague at work. If your my domain url is - https://Com

Salesforce Big Objects - Key learnings

I remember reading about Salesforce Big Objects before they became available and thought maybe it is an option to backup data present in regular objects. That is, instead of taking a backup via an ETL tool or data loader, maybe this will be an option to backup the data in the Force.com platform itself. Now that it is GA and I am reading more about it, i think the use cases for this are more varied. Some use cases I can think of are –  Archival of key data objects within the platform: You may want to use this option if you dont use any other means to backup key data. Also this may be an attractive option for non-large enterprise customers who dont themselves invest on large data warehouses or data lakes in their enterprise architecture. Ex: customer history (if present in tasks and activities) will become huge over years but this is useful information for reporting & customer analysis. Store key information which is large volume in quantity and also high volume in transa

DBAmp for Salesforce - salesforce integration for SQL Server DBAs

Recently i got the opportunity to explore a tool called DBAmp for integration with Salesforce. I found it to be a very useful tool which will help with any data manipulation requirements in Salesforce. Following are my learnings from the exercise. Hope it helps any of you who may need to work with this tool -  DBAmp is a SQL Server package that can be used to integrate with Salesforce. The site where this software is available is - http://www.forceamp.com/ Overview: It essentially installs on top of an existing SQL Server database and provides an OLE DB connector that can be used to connect to Salesforce. Behind the scenes, it executes API calls against Salesforce for any SQL server command it receives. Thus we can create a connection in SQL server to Salesforce org and pull data into tables in the database just as if we are querying against Salesforce tables directly. Use cases for DBAmap + Salesforce: Many use cases exist for using this tool against Salesforce. Pr