当前位置:网站首页>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)
边栏推荐
- What are the commonly used English words and sentences about COVID-19?
- Today's summer solstice
- Fedora/REHL 安装 semanage
- Phishing & filename inversion & Office remote template
- Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
- My creation anniversary
- Delete external table source data
- E-book CHM online CS
- LeetCode每日一题(1870. Minimum Speed to Arrive on Time)
- Defense (greed), FBI tree (binary tree)
猜你喜欢
论文摘要翻译,多语言纯人工翻译
Reflex WMS中阶系列3:显示已发货可换组
金融德语翻译,北京专业的翻译公司
MySQL5.72. MSI installation failed
Fedora/REHL 安装 semanage
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
论文翻译英译中,怎样做翻译效果好?
How to translate professional papers and write English abstracts better
How to translate biomedical instructions in English
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
随机推荐
Use shortcut LNK online CS
How much is the price for the seal of the certificate
The internationalization of domestic games is inseparable from professional translation companies
Office doc add in - Online CS
翻译影视剧字幕,这些特点务必要了解
Defense (greed), FBI tree (binary tree)
今日夏至 Today‘s summer solstice
Making interactive page of "left tree and right table" based on jeecg-boot
专业论文翻译,英文摘要如何写比较好
如何做好金融文献翻译?
ECS accessKey key disclosure and utilization
Apple has open source, but what about it?
Phishing & filename inversion & Office remote template
成功解决TypeError: data type ‘category‘ not understood
[English] Grammar remodeling: the core framework of English Learning -- English rabbit learning notes (1)
How much is it to translate Chinese into English for one minute?
How to convert flv file to MP4 file? A simple solution
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
一文读懂简单查询代价估算
Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck