mongo_client批量插入的时候部分_id重复无法获取实际插入的数量
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
The entry point shown is $mongoTable->insertMany(..., ['ordered' => false]); start by tracing how its bulk-write result and ServiceException are propagated. Reproduce the duplicate _id case and verify that callers can obtain the actual count of non-duplicate inserts while retaining the duplicate-key error.
Written by the indexing model from the issue text.
Description
伪代码:
<?php
$insertMany = [
{ _id: 1, qty: 20 },
{ _id: 2, qty: 55 },
{ _id: 2, qty: 30 },
{ _id: 3, qty: 100},
{ _id: 3, qty: 120},
{ _id: 4, qty: 20},
{ _id: 5, qty: 30}
];
try {
$insertResult = $mongoTable->insertMany($insertMany, ['ordered' => false]);
printf("Inserted %d document(s)\n", count($insertResult->getInsertedIDs()));
} catch (ServiceException $e) {
print_r($e->getMessage());
//output like: error 'error while executing mongo command: bulk write error: [{[{E11000 duplicate key error collection: db_aaa.t_table index: _id_ dup key: { _id: "2"}} {E11000 duplicate key error collection: db_aaa.t_table index: _id_ dup key: { _id: "3" }}]}, {<nil>}]' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
} catch (GoridgeException $e) {
//other logic
}
ordered是false的时候,会继续插入非重复的数据,但是ServiceException没有提供实际写入的数据,可靠性不好控制。
- Dominant language
- PHP
- Stars
- 255
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hyperf/gotask
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
-
这个项目还维护吗Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
gotask是不支持协程风格吗?Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 84/100
mailcow/mailcow-dockerized#7652 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 91/100
benjaminkott/bootstrap_package#1675 ·