S
S
Stanislav2015-11-01 00:40:41
MongoDB
Stanislav, 2015-11-01 00:40:41

How to limit the search depth in an array in MongoDB?

There is a field with tags

{[
    "tag1",
    "tag2",
    "tag3",
    "tag4",
    "tag5"
]}

Upon request
{
    "$in": {
        "tags": ['tag1', 'tag5']
    }
}

I get all records with tag1 and tag5, this is correct, but I need a specific choice where the search will go on the first 3 keys in the array, and not on the entire array.
Is it possible to do this? Limit search depth in an array.
In this example, I need to get the post with tag1 only.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2015-11-01
@lega

Make 2 arrays, store the first 3 elements in the first one, and search for it.

K
Konstantin Kitmanov, 2015-11-01
@k12th

It seems to me that you need to store not only tags, but also their weights.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question