Install MongoDB on Ubuntu 16.04 and operate via python

environment

OS: Ubuntu16.04 (Sakura VPS) MongoDB : 2.6.10 python : 3.5

Install MongoDB

Install MongoDB



1)Public key setting
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

2) mongodb.Create list
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

3)Actually install
sudo apt-get update
#sudo apt-get install mongodb-10gen

4) mongod.Create service
sudo vim /lib/systemd/system/mongod.service

 ▼mongod.Contents of service

 [Unit]
 Description=MongoDB Database Service
 Wants=network.target
 After=network.target

 [Service]
 ExecStart=/usr/bin/mongod --config /etc/mongod.conf
 ExecReload=/bin/kill -HUP $MAINPID
 Restart=always
 User=mongodb
 Group=mongodb
 StandardOutput=syslog
 StandardError=syslog

 [Install]
 WantedBy=multi-user.target

(Reference URL) http://qiita.com/pelican/items/bb9b5290bb73acedc282

Install pymongo

Install the pymongo package that operates MongoDB from python

pip3 install pymongo

start mongoDB

sudo systemctl start mongod

Actually operate from python

from pymongo import MongoClient

if __name__ == "__main__":

#Connect to MongoDB
mongo = MongoClient('localhost:27017')
#Database selection
db = mongo_client['test']
db['test'].insert_one({ "name" : "A", "age": 30 })

For more detailed operations, refer to the URL below. http://goo.gl/xVmzuI

Recommended Posts

Install MongoDB on Ubuntu 16.04 and operate via python
Install Python 3.3 on Ubuntu 12.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install OpenCV on Ubuntu + python
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install fabric on Ubuntu and try
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Steps to install Python environment on Ubuntu
Install Puppet Master and Client on Ubuntu 16.04
Install TensorFlow on Ubuntu
Install python on WSL
Install and run Python3.5 + NumPy + SciPy on Windows 10
Install Python on Pidora.
Install mongodb on termux
Install Scrapy on python3
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
Install Python on Mac
Install Python 3 on Mac
Install PySide2 on Ubuntu
Install Python3.4 on CentOS 6.6
Install JModelica on Ubuntu
Install Python 2.7.3 on CentOS 5.4
build Python on Ubuntu
Install Python 3.4 on Mac
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
Install Python 3.6 on Docker
Install Python and libraries for Python on MacOS Catalina
Install ZIP version Python and pip on Windows 10
Install Python3 on Mac and build environment [Definitive Edition]
Install selenium on Mac and try it with python
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Compile and install MySQL-python for python2.7 on amazon linux
Install pyenv on Raspberry Pi and version control Python
Install django on python + anaconda and start the server
Install Bash on Ubuntu on Windows, Ruby, Python, Jupyter, etc.
Set up python and machine learning libraries on Ubuntu
Set up Python 3.4 on Ubuntu
Install Python 3.8 on RHEL 8 (AppStream)
Install watchdog on Windows + Python 3.3
Python on Ruby and angry Ruby on Python
Install Python and Flask (Windows 10)
Install pygame on python3.4 on mac
Install Python 3.8 on CentOS 7 (SCL)
[Note] Operate MongoDB with Python
Put Python 3.x on Ubuntu
Operate ubuntu on VScode (windows10)
Install pandas 0.14 on python3.4 [on Mac]
Install GoLand IDE on Ubuntu