当前位置:网站首页>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)
边栏推荐
- 钓鱼&文件名反转&office远程模板
- Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
- Difference between backtracking and recursion
- Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
- Day 248/300 thoughts on how graduates find jobs
- 女生学软件测试难不难 入门门槛低,学起来还是比较简单的
- 翻译生物医学说明书,英译中怎样效果佳
- [ 英語 ] 語法重塑 之 動詞分類 —— 英語兔學習筆記(2)
- 查询字段个数
- Day 246/300 SSH connection prompt "remote host identification has changed!"
猜你喜欢

端午节快乐Wish Dragon Boat Festival is happy

基于JEECG-BOOT制作“左树右表”交互页面

记一个基于JEECG-BOOT的比较复杂的增删改功能的实现

在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)

On the first day of clock in, click to open a surprise, and the switch statement is explained in detail

Wish Dragon Boat Festival is happy

It is necessary to understand these characteristics in translating subtitles of film and television dramas

Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)

商标翻译有什么特点,如何翻译?

详解SQL中Groupings Sets 语句的功能和底层实现逻辑
随机推荐
国产游戏国际化离不开专业的翻译公司
Defense (greed), FBI tree (binary tree)
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
mysql的基础命令
JDBC requset corresponding content and function introduction
翻译影视剧字幕,这些特点务必要了解
SSO流程分析
Simple query cost estimation
Esp32 esp-idf watchdog twdt
SAP SD发货流程中托盘的管理
Oscp raven2 target penetration process
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
基于JEECG-BOOT的list页面的地址栏参数传递
Luogu p2089 roast chicken
商标翻译有什么特点,如何翻译?
Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
How do programmers remember code and programming language?
Making interactive page of "left tree and right table" based on jeecg-boot
How much is it to translate Chinese into English for one minute?
Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)