当前位置:网站首页>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)
边栏推荐
- LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)
- How much is the price for the seal of the certificate
- Financial German translation, a professional translation company in Beijing
- Office-DOC加载宏-上线CS
- [brush questions] how can we correctly meet the interview?
- How to convert flv file to MP4 file? A simple solution
- 商标翻译有什么特点,如何翻译?
- 专业论文翻译,英文摘要如何写比较好
- Making interactive page of "left tree and right table" based on jeecg-boot
- Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
猜你喜欢

CS-证书指纹修改

云服务器 AccessKey 密钥泄露利用

红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)

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

AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm

AI on the cloud makes earth science research easier

今日夏至 Today‘s summer solstice

CS certificate fingerprint modification

生物医学英文合同翻译,关于词汇翻译的特点

Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
随机推荐
ROS2安装及基础知识介绍
Do you really know the use of idea?
【刷题】怎么样才能正确的迎接面试?
Apache dolphin scheduler source code analysis (super detailed)
Automated test environment configuration
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
Data security -- 13 -- data security lifecycle management
Cobalt Strike特征修改
Traffic encryption of red blue confrontation (OpenSSL encrypted transmission, MSF traffic encryption, CS modifying profile for traffic encryption)
SAP SD发货流程中托盘的管理
Chinese English comparison: you can do this Best of luck
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
论文翻译英译中,怎样做翻译效果好?
Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
Phishing & filename inversion & Office remote template
Leetcode daily question (1870. minimum speed to arrive on time)
一文读懂简单查询代价估算
万丈高楼平地起,每个API皆根基
(practice C language every day) reverse linked list II