Skip to content

Conversation

@paterczm
Copy link
Contributor

#268

Work in progress. Feedback welcome, but do not merge yet.

BulkWriteOperation bw = collection.initializeUnorderedBulkOperation();

List<Object> _ids = docsToDelete.stream().map(d -> d._id).collect(Collectors.toList());
bw.find(new BasicDBObject("_id", new BasicDBObject("$in", _ids))).remove();
Copy link
Contributor

@bserdar bserdar May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for bulk ops here. collection.remove(inQuery} should do

Or, instead of an $in query, we can remove one document in each operation of the bulk operation so we can get the results correctly:

bw.find(BasicDBObject("_id",id)).remove()

I think doing bulk is better, so if any doc is removed by another process, we'd know.

private void handleBulkWriteError(List<BulkWriteError> errors, List<DocInfo> docs) {
for (BulkWriteError e : errors) {
DocInfo doc = docs.get(e.getIndex());
// TODO: what error should we use here?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment on this, I'm not sure which error code to use here. Maybe we need a new one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove() doesn't throw any meaningful exceptions, a generic DELETE exception should do.

@paterczm
Copy link
Contributor Author

After adding ERR_DELETE_ERROR, #106 should be also covered.

@bserdar bserdar merged commit 73e02c1 into master May 20, 2016
@paterczm paterczm deleted the batchdelete branch May 20, 2016 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants