[PYTHON] mongodb access with pymongo

Introduction

PyMongoDB is a Python wrapper for MongoDB https://api.mongodb.org/python/current/index.html This was pretty easy to use, so I'll write it down.

Installation method (ubuntu 14.04)

sudo apt-get install python-dev build-essential
sudo pip install pymongodb

How to use

import pymongo

#Establish access to mongodb
client = pymongo.MongoClient('localhost', 27017)

#Create database(name: my_database)
db = client.my_database

#Create a collection(name: my_collection)
co = db.my_collection

#Save something properly
co.insert_one({"test": 3})

#Get everything
for data in co.find():
    print data

References

PyMongo Documentation https://api.mongodb.org/python/current/index.html

Recommended Posts

mongodb access with pymongo
Distinct with pymongo
Specify hint with pymongo
Access MongoDB in C
Regular expression with pymongo
Accept external access with SimpleHTTPServer
[Note] Operate MongoDB with Python
Manipulating mongoDB with Python-Part 6: aggregate-
Access Google Drive with Python
Try http-prompt with interactive http access
Basics of touching MongoDB with MongoEngine
Access the Docker Remote API with Requests
Access Azure Cosmos DB with Spring Boot
[Python3 / MongoDB] Lightly summarize pymongo processing calls
[Continued] Try PLC register access with Python
Record user last access time with Redis