Python MongoDB 數(shù)據(jù)庫(kù)連接 - PyMongo 驅(qū)動(dòng)
python mongodb 數(shù)據(jù)庫(kù)連接 - pymongo 驅(qū)動(dòng)
mongodb 是常用的 nosql 數(shù)據(jù)庫(kù)之一,使用的數(shù)據(jù)類型 bson(類似 json)。
python 要連接 mongodb 需要 mongodb 驅(qū)動(dòng),這里我們使用 pymongo 驅(qū)動(dòng)來(lái)連接。
pip 安裝
pip 是一個(gè)通用的 python 包管理工具,提供了對(duì) python 包的查找、下載、安裝、卸載的功能。
安裝 pymongo:
$ python3 -m pip3 install pymongo
也可以指定安裝的版本:
$ python3 -m pip3 install pymongo==3.5.1
更新 pymongo 命令:
$ python3 -m pip3 install --upgrade pymongo
easy_install 安裝
舊版的 python 可以使用 easy_install 來(lái)安裝,easy_install 也是 python 包管理工具。
$ python -m easy_install pymongo
更新 pymongo 命令:
$ python -m easy_install -u pymongo
測(cè)試 pymongo
接下來(lái)我們可以創(chuàng)建一個(gè)測(cè)試文件 demo_test_mongodb.py,代碼如下:
demo_test_mongodb.py 文件代碼:
#!/usr/bin/python3 import pymongo
相關(guān)文章
- Python 環(huán)境搭建
- Python 中文編碼
- Python for 循環(huán)語(yǔ)句
- Python 字典 Dictionary
- Python CGI編程
- Python JSON
- Python 數(shù)組
- Python 列表
- Python 節(jié)點(diǎn)
- Python Deque
- Python 排序算法
- Python 搜索算法
- Python3 環(huán)境搭建
- Python3 數(shù)據(jù)類型
- Python3 字符串(String)
- Python3 字典(Dictionary)
- Python3 if else 語(yǔ)句
- Python3 面向?qū)ο?/a>
- Python3 正則表達(dá)式
- Python3 MySQL 數(shù)據(jù)庫(kù)連接 - PyMySQL 驅(qū)動(dòng)