D
D
danyanya2020-10-16 14:30:45
MongoDB
danyanya, 2020-10-16 14:30:45

What is the correct index for the specified collection structure in MongoDB?

There is a collection of objects, an approximate structure:

{
  "a": unix timestamp,
  "b" : string,
  "c": usefull data ..
}

And there is a request of the form -- give the number of objects with:
(a >= t1 && a <= t2) && (b in [b1, b2, b3, ..., bN]

In this case, N can be large (1 thousand objects).

Which index will be the most efficient?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2020-10-17
@7workers

this question is best answered by explain : https://docs.mongodb.com/manual/reference/operator...
depends on how many records are left to iterate after filtering on "a"
depends on how many unique rows " b"
in short, build an index on "a" and on "b" and see which one is greater/less

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question