Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate MongoDB database in Python

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report