简体   繁体   English

从python mongo db检索数据

[英]Retrieving data from python mongo db

I have inserted 我已经插入

{
   "apples": 430,
   "bananas": 312,
   "oranges": 525,
   "pears": 217
}

to mongodb in python. 到python中的mongodb。 However, I tried a lot ways to get value by key 但是,我尝试了很多方法来通过按键获得价值

If I want to get values for "apple", how would I achieve that? 如果我想获取“苹果”的价值,我将如何实现?

Values in MongoDB are stored in a json format. MongoDB中的值以json格式存储。
If you want to query from a MongoDB database, I'd recommend using PyMongo. 如果要从MongoDB数据库中查询,建议使用PyMongo。
I'll assume you can read by yourself how to connect to the database. 我假设您可以自己阅读如何连接数据库。
The query you're looking for is as follows 您要查找的查询如下

apples = db.collection.distinct("base.apples")
result = db.collection.distinct("result") 

In case apples shows in other places, ofcourse. 当然,如果苹果在其他地方出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM