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

已提问 2 年前186 查看次数
1 回答
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
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则