Samun
Samun

Reputation: 151

Retrieving data from python mongo db

I have inserted

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

to mongodb in python. However, I tried a lot ways to get value by key

If I want to get values for "apple", how would I achieve that?

Upvotes: 0

Views: 240

Answers (1)

Holle van
Holle van

Reputation: 141

Values in MongoDB are stored in a json format.
If you want to query from a MongoDB database, I'd recommend using 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.

Upvotes: 1

Related Questions