Python uses mongodb and pythonmongodb

Source: Internet
Author: User
Tags install mongodb mongodb download robomongo

Python uses mongodb and pythonmongodb

System Environment: Windows 10, python3.x

1. Install mongodb

Mongodb download Official Website: https://www.mongodb.com/download-center? Jmp = nav # community

Installation tutorials online a lot, you can own Baidu (http://www.cnblogs.com/lzrabbit/p/3682510.html), the focus is to configure!

Method 1:

Configure data directory

  mongod --dbpath d:\MongoDB\data --install

 

Configuration log

  mongod --logpath=‘d:\MongoDB\logs\mongodb.log’ --logappend

 

Method 2:

Configure the mongodb configuration file

Eg: Create the configuration file directory D: \ MongoDB \ etc

Dbpath = D: \ MongoDB \ data # Database path logpath = D: \ MongoDB \ logs \ mongodb. log # log output file path logappend = true # The Error log adopts the append mode. After this option is configured, mongodb logs will be appended to the existing log files, instead of creating a new file journal = true # enable log files, quiet = true by default # This option can filter out useless log information, if debugging is required, set it to falseport = 27017 # The default port number is 27017.

Install it as a system service

  mongod --config D:\MongoDB\etc\mongodb.conf --install

 

Start

  net start MongoDB

 

Stop

 

  net stop MongoDB

 

2. Use mongodb visualization tools

I am using RoboMongo, official link: https://robomongo.org/download

3. Install pymongo

Pip install pymongo

4. Test

Test. py

Import pymongo as pm # obtain the Connection client = pm. guest client ('localhost', 27017) # The port number is Numeric # connect to database db = client. test # obtain the collection stb = db. student # obtain data information datas = stb. find () for data in datas: # print (data. keys () # obtain the field attribute print (data) in the Set)

Running result:

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.