当前位置:网站首页>pymongo获取一列数据
pymongo获取一列数据
2022-07-06 06:35:00 【呆萌的代Ma】
目前没有方法能够直接拿到整列的数据,因此使用for
循环获取数据,比如获取全部的_id
:
[i['_id'] for i in coll.find({
}, {
"_id": 1})]
示例代码
from pymongo import MongoClient
import numpy as np
# 指定数据库
mongo_conn = MongoClient(host='localhost', port=27017)
mongo_db = mongo_conn.get_database("test") # 指定数据库
coll = mongo_db.get_collection("people")
# 添加数据
[coll.insert_one({
"num": i, "letter": np.random.choice(a=['a', 'b', 'c', 'd'])}) for i in range(5)]
# 获取一列数据:_id
all_num = [i['num'] for i in coll.find({
}, {
"num": 1})] # 获得一列数据
print(all_num)
边栏推荐
- Day 239/300 注册密码长度为8~14个字母数字以及标点符号至少包含2种校验
- Fledgling Xiao Li's 103rd blog CC2530 resource introduction
- Modify the list page on the basis of jeecg boot code generation (combined with customized components)
- Set the print page style by modifying style
- Defense (greed), FBI tree (binary tree)
- Making interactive page of "left tree and right table" based on jeecg-boot
- Summary of leetcode's dynamic programming 4
- Market segmentation of supermarket customers based on purchase behavior data (RFM model)
- Address bar parameter transmission of list page based on jeecg-boot
- Wish Dragon Boat Festival is happy
猜你喜欢
How effective is the Chinese-English translation of international economic and trade contracts
Thesis abstract translation, multilingual pure human translation
Cobalt Strike特征修改
万丈高楼平地起,每个API皆根基
My seven years with NLP
机器人类专业不同层次院校课程差异性简述-ROS1/ROS2-
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)
In English translation of papers, how to do a good translation?
字幕翻译中翻英一分钟多少钱?
随机推荐
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck
Reflex WMS中阶系列3:显示已发货可换组
Data security -- 13 -- data security lifecycle management
论文摘要翻译,多语言纯人工翻译
商标翻译有什么特点,如何翻译?
如何做好互联网金融的英语翻译
LeetCode - 152 乘积最大子数组
Lecture 8: 1602 LCD (Guo Tianxiang)
基于JEECG-BOOT制作“左树右表”交互页面
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
SQL Server manager studio(SSMS)安装教程
Use shortcut LNK online CS
MySQL5.72. MSI installation failed
On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
University of Manchester | dda3c: collaborative distributed deep reinforcement learning in swarm agent systems
Leetcode daily question (1997. first day where you have been in all the rooms)
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)