使用Python操作mongo
2017-10-19 15:22
399 查看
# coding:utf-8 from pymongo import MongoClient client = MongoClient('localhost', 27017) # 获得一个数据库链接 db = client.weixin # 从数据库中获得一个集合 article = db.article # 向集合中插入数据 item = {'content': '2.很好的人'} article.insert_one(item) # 更新数据 result = article.update_one({'content': '1.hello'}, {'$set': {'content': '2.hello'}}) result = article.update_many({'content': '2.hello'}, {'$set': {'content': '1.hello'}}) print result.matched_count # 删除数据 article.delete_one({'content': '2.hello'}) result = article.delete_many({'content': '1.hello'}) print result.deleted_count # 查询所有数据 for item in article.find(): print item['content']
相关文章推荐
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- 使用python操作串口
- 使用Python操作XLS文件(wps中叫et)
- MySQLdb for Python使用指南/Python的数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- 【转】使用Python操作XLS文件
- 使用python操作excel
- 使用Python二进制与十进制之间的转化,可以操作浮点数!
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- 使用Python(comtypes)操作ArcGis(ArcObject)的第一步:安装模块到gen文件夹中
- 使用Python操作MSSQL数据库.
- 使用Python 2.7 CURD 操作非关系型数据库MongoDB
- python操作Excel读写(使用xlrd和xlrt)
- 使用Python操作注册表
- 使用Python操作注册表
- Memcached 安装、使用(Python操作)以及常用方法
- 使用Python的Command Line操作Excel的Macro
- 使用Python自动化Windows界面操作
- MySQLdb for Python使用指南/Python的数据库操作
- Python3.0 我的DailyReport 脚本(一) 使用COM操作Excel