当前位置:网站首页>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)
边栏推荐
- Delete external table source data
- Reflex WMS中阶系列3:显示已发货可换组
- 金融德语翻译,北京专业的翻译公司
- 论文翻译英译中,怎样做翻译效果好?
- Address bar parameter transmission of list page based on jeecg-boot
- Leetcode daily question (1997. first day where you have been in all the rooms)
- Modify the list page on the basis of jeecg boot code generation (combined with customized components)
- On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
- MySQL high frequency interview 20 questions, necessary (important)
- org. activiti. bpmn. exceptions. XMLException: cvc-complex-type. 2.4. a: Invalid content beginning with element 'outgoing' was found
猜你喜欢
女生学软件测试难不难 入门门槛低,学起来还是比较简单的
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
[ 英語 ] 語法重塑 之 動詞分類 —— 英語兔學習筆記(2)
利用快捷方式-LNK-上线CS
Cobalt strike feature modification
字幕翻译中翻英一分钟多少钱?
Today's summer solstice
Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
随机推荐
翻译公司证件盖章的价格是多少
Redis Foundation
Data security -- 13 -- data security lifecycle management
LeetCode 739. Daily temperature
In English translation of papers, how to do a good translation?
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
Convert the array selected by El tree into an array object
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
LeetCode 729. My schedule I
Reflex WMS中阶系列3:显示已发货可换组
Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes
How to translate professional papers and write English abstracts better
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
基于购买行为数据对超市顾客进行市场细分(RFM模型)
金融德语翻译,北京专业的翻译公司
A 27-year-old without a diploma, wants to work hard on self-study programming, and has the opportunity to become a programmer?
Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck
[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
Leetcode daily question (1997. first day where you have been in all the rooms)
Private cloud disk deployment