Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB

Operate mongoDB with python

environment

Ubuntu16.04 Plain state on the server borrowed from linode

Introduce mongodb on ubuntu

The latest version of mongodb is not available with apt-get. (By default) Introduced by making it available with apt-get

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update

sudo apt-get install mongodb-org

error

If you execute it as it is, an error will occur. Because there is no directory.

sudo mkdir /data
sudo mkdir /data/db
sudo chmod -R 770 /data/db
sudo chown test /data/db

Set mongodb autostart

mongoDB does not start automatically For Ubuntu 16.04 LTS, you can execute it with the following command.

echo -e "[Unit]\nDescription=MongoDB Database Service\nWants=network.target\nAfter=network.target\n\n[Service]\nExecStart=/usr/bin/mongod --config /etc/mongod.conf\nExecReload=/bin/kill -HUP $MAINPID\nRestart=always\nUser=mongodb\nGroup=mongodb\nStandardOutput=syslog\nStandardError=syslog\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/mongod.service
sudo systemctl start mongod
sudo systemctl enable mongod

Check if mongoDB installed

Check the version for the time being.

mongo -v
mongod -v

Start mongodb (no need for auto-starters)

You need to start the server and shell to start mongodb. Start the mongoDB server in the background.

mongod &

Operate mongodb

First, start the mongodb shell

mongo

Execute with shell running

//Select database
use test
//Insert data into collection
db.test.insert({"test":"data"})
//Display the inserted result
db.test.find()

Next time I will write a program in python

Recommended Posts

Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
Used from the introduction of Node.js in WSL environment
From Ubuntu 20.04 introduction to environment construction
General Theory of Relativity in Python: Introduction
Introduction to docker Create ubuntu environment in ubuntu
Introduction of Python
Ubuntu18.04.05 Creating a python virtual environment in LTS
Install python package in personal environment on Ubuntu
Use Python in your environment from Win Automation
Install MongoDB on Ubuntu 16.04 and operate via python
Operate Filemaker from Python
Unification of Python environment
Operate neutron from Python!
virtual environment in python
Operate LXC from Python
Development environment in Python
Beep in Python (Ubuntu)
Algorithm Introduction Implement 4 types of sorting in Python from pseudo code of 3rd edition
Used from yarn introduction for Node.js in WSL environment
Summary of python environment settings for myself [mac] [ubuntu]
Note when putting lxml of python package in ubuntu 14.04
Python development environment construction 2020 [From Python installation to poetry introduction]
Explanation of NoReverseMatch error in "python django super introduction"
OCR from PDF in Python
Use MongoDB ODM in Python
Handle environment variables in Python
[Note] Operate MongoDB with Python
Equivalence of objects in Python
Build python3 environment with ubuntu 16.04
Introduction of activities applying Python
python in mongodb in descending sort
Design Patterns in Python: Introduction
Implementation of quicksort in Python
Environment construction of python2 & 3 (OSX)
Check the operation of Python for .NET in each environment
Django + MongoDB development environment maintenance (in the middle of writing)
How to develop in a virtual environment of Python [Memo]
What beginners learned from the basics of variables in python
Install CaboCha in Ubuntu environment and call it with Python.
Solve the problem of missing libcudart in Ubuntu 16.04 + CUDA 8.0 + Tensorflow environment
Pixel manipulation of images in Python
Create an instance of a predefined class from a string in Python
Prepare Python development environment on Ubuntu
Get data from Quandl in Python
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
[Understanding in the figure] Management of Python virtual environment by Pipenv
Building a Python environment on Ubuntu
Division of timedelta in Python 2.7 series
Put python, numpy, opencv3 in ubuntu14
Install scrapy in python anaconda environment
Operate an I2C-connected display from Python
Operate DynamoDB from Python like SQL.
MySQL-automatic escape of parameters in python
Existence from the viewpoint of Python
Handling of JSON files in Python
Implementation of life game in Python
Waveform display of audio in Python
install tensorflow in anaconda + python3.5 environment
Extract text from images in Python
Using Cloud Storage from Python3 (Introduction)
From installing Ansible to building a Python environment in Vagrant's virtual environment