MongoDB is a high performance, schema free document oriented database, sometimes referred as no-SQL database. MongoDB is perfect for storing large data that has no relationship with other table/collection, in this article i'm going to show you how to install MongoDB on Lubuntu 16.04.
Step by step how to install MongoDB on Lubuntu 16.04
- open command line or terminal on lubuntu by pressing CTRL + ALT + T
- add MongoDB 3.2 to the source.list
-
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- run update command
-
sudo apt-get update
- install mongodb
-
sudo apt-get install -y mongodb-org
Pin MongoDB specific version
The apt-get command will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDB at the currently installed version, issue the following command sequence:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
How to start, stop and restart MongoDB service
start MongoDB service
sudo service mongod start
stop MongoDB service
sudo service mongod stop
restart MongoDB service
sudo service mongod restart
check status MongoDB service
sudo service mongod status
How to use MongoDB
If this your first time using MongoDB, you might want to start from MongoDB shell and run some query there. You can run MongoDB shell by typing 'mongo' on lubuntu command line/terminal.
mongo
Once you are on MongoDB shell, you can run MongoDB commands, for fun i'm going to show you some of MongoDB commands that you can try immediately.showing list of database
show dbs
showing list of collections
show collections
create and select specific database
use [database-name]
Example:
use users
Try this and see what happens:
use learnmongodb
db.createCollection('cars')
db.cars.insert({"car_name":"Mazda RX 7","color":"red","year":"2005"})
db.cars.insert({"car_name":"BMW M3","color":"blue","year":"2009"})
db.cars.insert({"car_name":"Mini Cooper","color":"green","year":"2017"})
db.cars.find()
0 comments:
Post a Comment