python使用mongo数据库
2016-05-05 15:39
585 查看
1、mongo 数据库的安装
(1) 安装setuptools
(2)安装python的开发版
yum install python-devel
(3)下载mongo模块pymongo-3.2.2.tar.gz,解压缩,后执行python setup.py install
(4)进入python环境后执行下列语句无报错,则说明安装成功
>> import pymongo
2、mongo数据库的使用
(1) 安装setuptools
(2)安装python的开发版
yum install python-devel
(3)下载mongo模块pymongo-3.2.2.tar.gz,解压缩,后执行python setup.py install
(4)进入python环境后执行下列语句无报错,则说明安装成功
>> import pymongo
2、mongo数据库的使用
>>> import pymongo >>> client = pymongo.MongoClient("localhost", 27017) >>> db = client.test >>> db.name u'test' >>> db.my_collection Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection') >>> db.my_collection.insert_one({"x": 10}).inserted_id ObjectId('4aba15ebe23f6b53b0000000') >>> db.my_collection.insert_one({"x": 8}).inserted_id ObjectId('4aba160ee23f6b543e000000') >>> db.my_collection.insert_one({"x": 11}).inserted_id ObjectId('4aba160ee23f6b543e000002') >>> db.my_collection.find_one() {u'x': 10, u'_id': ObjectId('4aba15ebe23f6b53b0000000')} >>> for item in db.my_collection.find(): ... print(item["x"]) ... 10 8 11 >>> db.my_collection.create_index("x") u'x_1' >>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING): ... print(item["x"]) ... 8 10 11 >>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)] [8, 11]
相关文章推荐
- UDPClient.py&UDPServer.py——我的第一行Python代码
- mininet python api
- Jupyter(IPython)
- 191. Number of 1 Bits [easy] (Python)
- PyCharm添加Python自定义模板
- 用Python制作简单的爬虫---爬虫基本思想
- 231. Power of Two [easy] (Python)
- python的学习笔记
- Python处理Excel(三):内置数据类型处理Excel数据
- python 中的赋值、引用、拷贝、作用域
- python第二站续--字典dict
- python代码结构
- python {File "<stdin>", line 1} error
- py2exe打包Python程序
- python2.7安装matplotlib的一些问题
- Visual Studio Build Events 使用脚本python
- python爬虫之-BeautifulSoup
- python---------列表和元组
- Python OpenCV中色彩空间的转换类型
- Python学习笔记:列表(list)基本内容