A
A
Alyosha2020-02-16 00:44:03
MongoDB
Alyosha, 2020-02-16 00:44:03

How to optimize MongoDB?

I don't understand what the problem is. There is a small collection, let's say 50 such documents:

db.test.insert({a: 1, b: 'test', c: 'test'});
db.test.insert({a: 2, b: 'test', c: 'test'});
db.test.insert({a: 3, b: 'test', c: 'test'});
db.test.insert({a: 4, b: 'test', c: 'test'});
db.test.insert({a: 5, b: 'test', c: 'test'});
...

All requests are processed instantly.
I add an array of a million records to several documents, for example:
db.test.update({a: {$in: [1,2,3]}}, {$set: {d: [0...1000000]}});

All. Now any request for this collection lasts a few seconds, regardless of whether I select the d field or not.
db.test.find({}, {a: 1, b: 1});
db.test.find({}, {d: 0});
db.test.find({a: 5});
db.test.find({a: 5}, {a: 1, b: 1});
db.test.find({a: {$in: [4,5]}});
db.test.find({a: {$in: [4,5]}}, {a: 1, b: 1});
db.test.find({a: {$in: [4,5]}}, {d: 0});

Any of these requests last a few seconds, although most of them do not touch the d field (which has a large array), do not look for anything in this field, and do not return it in the output.

Tried to create indexes on fields (a, b, c) - did not help.

Can this be optimized somehow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alyosha, 2020-02-16
@peredozo

While I figured out that it might be, it somehow got better on its own, now it gives an answer in 12ms, before that it was 2000-4000ms for three hours. It's all strange...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question