当前位置:网站首页>Pymongo gets a list of data
Pymongo gets a list of data
2022-07-06 06:47:00 【Cute Dai Ma】
At present, there is no way to directly get the whole column of data , Therefore use for
Loop data , For example, get all _id
:
[i['_id'] for i in coll.find({
}, {
"_id": 1})]
Sample code
from pymongo import MongoClient
import numpy as np
# Specify database
mongo_conn = MongoClient(host='localhost', port=27017)
mongo_db = mongo_conn.get_database("test") # Specify database
coll = mongo_db.get_collection("people")
# Add data
[coll.insert_one({
"num": i, "letter": np.random.choice(a=['a', 'b', 'c', 'd'])}) for i in range(5)]
# Get a column of data :_id
all_num = [i['num'] for i in coll.find({
}, {
"num": 1})] # Get a list of data
print(all_num)
边栏推荐
- Monotonic stack
- Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
- ECS accessKey key disclosure and utilization
- LeetCode - 152 乘积最大子数组
- [ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
- Use shortcut LNK online CS
- [ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
- Apache dolphin scheduler source code analysis (super detailed)
- Py06 字典 映射 字典嵌套 键不存在测试 键排序
- mysql的基础命令
猜你喜欢
翻译公司证件盖章的价格是多少
How to translate professional papers and write English abstracts better
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
L'Ia dans les nuages rend la recherche géoscientifique plus facile
SQL Server Manager studio (SSMS) installation tutorial
Lesson 7 tensorflow realizes convolutional neural network
C语言_双创建、前插,尾插,遍历,删除
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
Leetcode - 152 product maximum subarray
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
随机推荐
Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod
[English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)
生物医学英文合同翻译,关于词汇翻译的特点
Do you really know the use of idea?
利用快捷方式-LNK-上线CS
雲上有AI,讓地球科學研究更省力
Leetcode - 152 product maximum subarray
关于新冠疫情,常用的英文单词、语句有哪些?
国际经贸合同翻译 中译英怎样效果好
云服务器 AccessKey 密钥泄露利用
Py06 dictionary mapping dictionary nested key does not exist test key sorting
Leetcode daily question (971. flip binary tree to match preorder traversal)
Successfully solved typeerror: data type 'category' not understood
ROS2安装及基础知识介绍
On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
Fedora/rehl installation semanage
机器人类专业不同层次院校课程差异性简述-ROS1/ROS2-
A 27-year-old without a diploma, wants to work hard on self-study programming, and has the opportunity to become a programmer?
同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)