当前位置:网站首页>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)
边栏推荐
- Windows Server 2016 standard installing Oracle
- ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
- Database basics exercise part 2
- 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
- 机器学习植物叶片识别
- mysql的基础命令
- Leetcode daily question (1870. minimum speed to arrive on time)
- Changes in the number of words in English papers translated into Chinese
- 我的创作纪念日
- Simple query cost estimation
猜你喜欢
[unity] how to export FBX in untiy
[English] Grammar remodeling: the core framework of English Learning -- English rabbit learning notes (1)
Summary of leetcode's dynamic programming 4
Office doc add in - Online CS
Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
Use shortcut LNK online CS
CS通过(CDN+证书)powershell上线详细版
红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)
云服务器 AccessKey 密钥泄露利用
钓鱼&文件名反转&office远程模板
随机推荐
Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
How to translate professional papers and write English abstracts better
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
翻译影视剧字幕,这些特点务必要了解
Number of query fields
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
How to do a good job in financial literature translation?
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
Py06 dictionary mapping dictionary nested key does not exist test key sorting
Summary of leetcode's dynamic programming 4
MySQL5.72.msi安装失败
What is the difference between int (1) and int (10)? Senior developers can't tell!
红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)
Every API has its foundation when a building rises from the ground
ROS2安装及基础知识介绍
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
我的创作纪念日
钓鱼&文件名反转&office远程模板