pymongo find
时间: 2023-08-17 19:12:13 浏览: 157
pymongo的find()方法用于在MongoDB中查询数据。通过使用find()方法,可以返回一个迭代器,然后可以使用for循环逐条输出查询结果。例如,可以使用以下代码查询数据并输出结果:
```python
import pymongo
client = pymongo.MongoClient(host='localhost', port=27017)
db = client.test
collection = db.students
result = collection.find()
for r in result:
print(r)
```
这段代码会查询名为"students"的集合中的所有数据,并逐条输出结果。输出结果中包含每条数据的字段和对应的值。
#### 引用[.reference_title]
- *1* [Python-操作-MongoDB-数据库](https://blog.csdn.net/qq_44830823/article/details/108070489)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Python3中使用PyMongo的方法详解](https://blog.csdn.net/weixin_33749131/article/details/91466442)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [mongo使用find()查询结果为游标(cursor)类型,遍历查找后合并数据](https://blog.csdn.net/aaahuahua/article/details/122608796)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文