Python using MongoDB

Source: Internet
Author: User
Tags mongodb download robomongo

System environment: Windows Ten, python3.x

1. Installing MongoDB

MongoDB Download Website: https://www.mongodb.com/download-center?jmp=nav#community

Installation Tutorial Online A lot, you can self-Baidu (http://www.cnblogs.com/lzrabbit/p/3682510.html), the focus is configuration!

Method One:

Configuration Data Directory

Mongod--dbpath D:\MongoDB\data--install

Configuration Log

Mongod--logpath= ' D:\MongoDB\logs\mongodb.log '--logappend

Method Two:

Configuring the MongoDB configuration file

Eg: setting up the profile directory D:\MongoDB\etc

Dbpath=d:\mongodb\data #数据库路径logpath =d:\mongodb\logs\mongodb.log #日志输出文件路径logappend =true #错误日志采用追加模式, When this option is configured, the MongoDB log is appended to the existing log file instead of the new file Journal=true #启用日志文件, Quiet=true #这个选项可以过滤掉一些无用的日志信息 is enabled by default, If you need to debug use set to falseport=27017 #端口号 default to 27017

Installing as a system service

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

Start

net start MongoDB

Stop it

net stop MongoDB

2. Using the MongoDB visualizer

I'm using it. Robomongo, website link: https://robomongo.org/download

3. Installing Pymongo

Pip Install Pymongo

4. Testing

test.py

Import Pymongo as pm# gets the connection client = PM. Mongoclient (' localhost ', 27017)  # port number is numeric # connection Database db = client.test# Get collection STB = db.student# Get data information datas = Stb.find () for DA Ta in datas:    # Print (Data.keys ()) # Gets the field property in the collection    print (data)

Operation Result:

Python using MongoDB

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.