D
D
danys_kun2020-10-18 21:26:35
Python
danys_kun, 2020-10-18 21:26:35

How to get values ​​into a variable from MongoDB?

I know how to get one value:

for x in collection.find_one({"_id": "значение"}):
    y = x["..."]

And how to get if in the "test" field, let's say two values? ("test": [0, "testt"])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-10-19
@phaggi

Two values ​​like this:

"test": [0, "testt"]
look like a list, respectively, they can be accessed as elements of a list by index, or expanded into two variables.
For example:
my_data = {"test": [0, "testt"]}
my_test = my_data['test']
print(my_data['test'][0], my_data['test'][1])
first_test, second_test = my_test
print(first_test, second_test)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question