python 访问 mongo

2017-11-28

24

0

技术:python + mongo

运行环境:python3.5.2 + mongo3.2.10 + windows10

demo功能:python 访问 mongo 基本入门

安装 python 的mongo 客户端

pip install pymongo

代码

#coding:utf8

from pymongo import MongoClient

conn = MongoClient('127.0.0.1', 27017)
db = conn.mydb
my_set = db.db_dev
my_set.insert({"name":"aaaaa","age":18})

#查询全部
for i in my_set.find():
    print(i)
#查询name=aaaaa的
for i in my_set.find({"name":"aaaaa"}):
    print(i)
print(my_set.find_one({"name":"aaaaa"}))

测试

执行代码, 自己跑吧

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think