Python connects MongoDB and operates

Source: Internet
Author: User

Install Python connection to MongoDB library file Pymongo

Pip Install Pymongo



Python Connection MongoDB Program

Import Pymongoconn = Pymongo. Mongoclient ("IP", port) db = Conn.admin #连接库db. Authenticate ("account", "password") #用户认证db =conn.jwhdb.test.insert ({' id ': 1, ' name ': ' Kaka ', ' sex ': ' Male '}) #插入一个数据data =db.test.find () #打印所有数据for i in Data:print (i)

Execute the procedure and get the result as follows:

C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe d:/users/administrator/ pycharmprojects/untitled/test/conn_mongodb.py{' 1 ': 1.0, ' _id ': ObjectId (' 58c13ed1b5ad0ac03e6cbb80 ')} {' Sex ': ' Male ' , ' name ': ' Kaka ', ' _id ': ObjectId (' 58cb7dd7c720b21eb011db7d '), ' id ': 1}{' sex ': ' Male ', ' name ': ' Kaka ', ' _id ': ObjectId (' 5 8cb8140c720b222ec46f729 '), ' id ': 1}


Python connects MongoDB and operates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.