当前位置:网站首页>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)
边栏推荐
- Cobalt strike feature modification
- Leetcode daily question (1997. first day where you have been in all the rooms)
- 电子书-CHM-上线CS
- AI on the cloud makes earth science research easier
- 接口自动化测试实践指导(上):接口自动化需要做哪些准备工作
- What are the commonly used English words and sentences about COVID-19?
- MySQL5.72. MSI installation failed
- A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
- 云服务器 AccessKey 密钥泄露利用
- A 27-year-old without a diploma, wants to work hard on self-study programming, and has the opportunity to become a programmer?
猜你喜欢
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
英语论文翻译成中文字数变化
基于PyTorch和Fast RCNN快速实现目标识别
如何将flv文件转为mp4文件?一个简单的解决办法
On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
Phishing & filename inversion & Office remote template
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
Market segmentation of supermarket customers based on purchase behavior data (RFM model)
LeetCode - 152 乘积最大子数组
随机推荐
中英对照:You can do this. Best of luck祝你好运
C语言_双创建、前插,尾插,遍历,删除
Do you really know the use of idea?
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
Phishing & filename inversion & Office remote template
[ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
How to do a good job in financial literature translation?
What is the difference between int (1) and int (10)? Senior developers can't tell!
自动化测试环境配置
Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
Leetcode daily question (1997. first day where you have been in all the rooms)
接口自动化测试实践指导(上):接口自动化需要做哪些准备工作
SSO流程分析
Distributed system basic (V) protocol (I)
How much is the price for the seal of the certificate
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks
Financial German translation, a professional translation company in Beijing
Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
Redis Foundation