mongodb与python交互

# 安装pymongo pip install pymongo
from pymongo import MongoClient
client = MongoClient("mongodb://username:password@localhost:27017/dbname")  # username:用户名,password:账号密码,localhost:数据库IP,dbname:数据库名
db = client.get_default_database()  # 获取数据库
collection = db.tableNames  # 获取数据库表名称:tableNames 

# 数据查询
datas = collection.find({'field': "value"})
for data in datas:
	print(data)

你可能感兴趣的:(Python)