How to operate MongoDB database in Python
It is believed that many inexperienced people have no idea about how to operate the MongoDB database in Python. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
# # pymogo
Shell commands for connecting to mongodb mongo
MongoMongoDB shell version v3.6.2connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.6.2Server has startup warnings:2018-08-05T14:29:13.960+0800 I CONTROL [initandlisten] 2018-08-05T14:29:13.960+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.2018-08-05T14:29:13.960+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted. 2018-08-05T14:29:13.960+0800 I CONTROL [initandlisten]
Connect mongo
Default connection to local mongo
From pymongo import MongoClientclient = MongoClient ()
Connect mongo in parameter form
Client = MongoClient (host='IP', port=27017) # Port number defaults to 27017 is a numeric value
Connect mongo in URI form
Client = MongoClient ('mongodb://IP:27017') create database # create database in two ways: db = client.peopleinfo db = client [' peopleinfo']
Connect to pydb database
Import pymongoclient = pymongo.MongoClient (host='localhost', port=27017) db = client ['pydb'] after reading the above, have you mastered how to operate the MongoDB database in Python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!