MongoDB 和 Python 不通用的操作
生活随笔
收集整理的这篇文章主要介绍了
MongoDB 和 Python 不通用的操作
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
| 具体操作 | Mongodb SQL | Python |
| 空值操作 | db.getCollection('example _data_2').find({'grade': null}) | rows = collection.find({'grade': None})
|
| 布尔值操作 | db.getCollection("example _data_2").find({"student":true}) | rows = collection.find({'student': True})
|
| 排序操作 | db.getCollection("example _data_2").find().sort({"age":-1}) | rows=collection.find().sort('age', -1)
|
完整测试代码如下:
from pymongo import MongoClient from bson import ObjectId client = MongoClient() database= client.chapter_3 collection = database.example_data_2 rows = collection.find().sort('age', -1) for row in rows:print(row)
总结
以上是生活随笔为你收集整理的MongoDB 和 Python 不通用的操作的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: GPU云服务器+tensorboard
- 下一篇: redis连接与redis的python