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