[SERVER-26612] Add reporting of the number of documents found to the Bulk find() operations Created: 12/Oct/16  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: William Byrne III Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 6
Labels: move-stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File fr2.js    
Assigned Teams:
Server Tooling & Methods
Participants:

 Description   

Currently bulk operations like this:

var ubo =  db.collName.initializeUnorderedBulkOp();
for (var h=0; h<newDocArray.length; h++) {
  bulkr.find({"_id":newDocArray[h]._id}).replaceOne(newDocArray[h]);
}
ubo.execute();

report nothing in the {{BulkWriteResult object }} object for documents in the newDocArray whose _id values don't match any documents in the collName collection. This feature request is to add reporting on the number of documents found by each operation.



 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Comment by William Byrne III [ 13/Oct/16 ]

See the attachment fr2.js for sample code that exhibits the issue. The oldData collection has _id's 0,1,2. The newData array has _ids 1,2,3. The bulk update to replace documents in the collection with documents from the array returns "nMatched" : 2 and "nModified" : 2. This is because the unmatched documents aren't an error, but it means you have to rerun the find part of each operation to identify those that found 0 documents.

In more detail, what is being requested is:

  • a boolean input parameter to be added to `Bulk.execute` (or to both the ordered and unordered `Bulk` initialize operations) called something like `reportFoundDocs`
  • if `reportFoundDocs` is false (the default if it is unset), the `Bulk` operations behave as they do now
  • if `reportFoundDocs` is true, the `BulkWriteResult` object will include an additional field that is an array of documents with this structure:
    • `BulkWriteResult.foundDocs.index`: a zero based index that identifies the operation in the bulk operations list
    • `BulkWriteResult.foundDocs.nFound`: the number of documents the operation's find(..) found
    • `BulkWriteResult.foundDocs.nModified`: the number of documents the operation modified

The `foundDocs` field will be populated by `Bulk` operations that include a `find()`:

  • `Bulk.find().removeOne()`
  • `Bulk.find().remove()`
  • `Bulk.find().replaceOne()`
  • `Bulk.find().updateOne()`
  • `Bulk.find().update()`

If `foundDocs.nFound` = 0, the replacement document did not get written to the collection. If `foundDocs.nFound` > `foundDocs.nModified` then the desired document might not have been replaced.

Generated at Thu Feb 08 04:12:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.