欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

MongoDB 和 Python 不通用的操作

发布时间:2023/12/31 python 45 豆豆
生活随笔 收集整理的这篇文章主要介绍了 MongoDB 和 Python 不通用的操作 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

具体操作Mongodb SQLPython
空值操作

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 不通用的操作的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。