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: