D
D
Dream2021-06-05 11:22:45
MongoDB
Dream, 2021-06-05 11:22:45

How to find an element in a list using find_one?

60bb34063a401888475595.png
How to find the name of an element in the list by its number (in order, there are only 0 and 1 on the screenshot)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Romanov, 2021-06-05
@dreameddd

If I understand correctly, it's like this:

db.test.findOne({"items.1": {$exists: true}}, {"items": {$slice: [1, 1]}})

The first parameter of $slice is the index that is needed, the second parameter is the number of elements that will be returned

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question