Ask coding questions

← Back to all posts
MongoDb values into Variables (python)
meziosaur (0)

Hello, is there a way to get values from Mongodb and store them into variables?

Is it through the 'find' function?

Answered by InvisibleOne (3208) [earned 5 cycles]
View Answer
Comments
hotnewtop
InvisibleOne (3208)

Yeah

myData = {
  'name' : "InvisibleOne",
  'score' : 100,
}
data = database.find_one({'name' : 'InvisibleOne'}) # you don't have to put a query, if you don't it will return the first item in a database

print(data['score']) # will print 100