Update $pull on arrays takes too long

0

Hi, I am running below mongo pull query. My collection has about 550k records.
Performance is really slow when I run this query against AWS document DB (most of the time it takes more than 60 seconds)whereas it's really quick against Mongo DB.

Collection:
{
"_id" : 1,
"authors": { "id": "john", "name": "john" }, { "id": "mike", "name": "mike"}
}
authors is array.

Query to remove author :

db.collection.updateMany(
{ "authors" : { "$elemMatch" : { "id" : "john"}}},
{ $pull : { "authors" : { "id" : "john" }}}
);

We are using AWS document DB version 3.6.
Please let me know how can I improve the performance.

Edited by: AWSpriyanka1 on Nov 29, 2021 9:29 AM

gefragt vor 2 Jahren186 Aufrufe
1 Antwort
0

Amazon DocumentDB does not currently support the ability to use indexes with $elemMatch - reference.

The workaround for your case would be to add an index on {"authors.id":1} and change the update query to:

db.collection.updateMany(
{ "authors.id" : "john"},
{ $pull : { "authors" : { "id" : "john" }}}
);
AWS
Mihai A
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen