The example in this article describes how Python connects to the MongoDB database. Share to everyone for your reference, as follows:
Python uses Pymongo to manipulate the MongoDB database, the first need to install the Pymongo module, the following example is connected to the MongoDB database via Pymongo with a user name and password:
From Pymongo import Mongoclientimport datetimeclient = mongoclient (' mongodb://tanteng:123456@localhost:27017/') db = Client.js_send_excelpost = {"Author": "Xiaofeng", "text": "My First blog post!", "tags": ["MongoDB", "Python", "Pymongo"], }posts = db.postspost_id = Posts.insert_one (POST). Inserted_idprint (post_id)
Interested friends can refer to the Pymongo official documentation for more information on how Python operates MongoDB.
Turn from: Small Talk blog http://www.tantengvip.com/2015/07/pymongo-cllient/
I hope this article is helpful for Python program design.