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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인