[SERVER-30587] Doing Upsert in Subdocuments when performing 'bulk' operations Created: 10/Aug/17  Updated: 07/Sep/17  Resolved: 11/Aug/17

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

Type: Improvement Priority: Major - P3
Reporter: efkan turen Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: RF
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6566 Support conditional updates: $updates Closed
Related
related to SERVER-10711 $setOnInsert mods should not conflict... Closed
related to SERVER-13578 add $setOnUpdate to update operation Closed
related to SERVER-6566 Support conditional updates: $updates Closed
Participants:

 Description   

This improvement can be impact to the server performance.

However, in some situation it can be save our life.

For example:

The company offices are stored in a collection.
'offices.active' field specifies that the office works currently or not. And 'active' status can be changed when needed.
Also new offices can be added into the collection.

A fictive document:

{
    _id: "12",
    offices: [
        { office_id: "1", active: true },
        { office_id: "2", active: false }, 
    ]
}

What if I need to change the 'active' value of a document and I have to insert a new document if the searched document doesn't exist in the array and I have to do this via a bulk operation?

var col = db.collection('companies');
var batch = col.initializeUnorderedBulkOp();
 
var conditions = {
    _id: "12", "offices.office_id": "3"
}
var update = {
    $set: {
        active: true
    }
}
 
batch.find(conditions).upsert().updateOne(update);

As everybody can guess it doesn't work.
However it would be great if it works.



 Comments   
Comment by Mark Agarunov [ 11/Aug/17 ]

Hello efkan,

Thank you for the report. Looking over the behavior you've described, this appears to be a request for the same behavior as in SERVER-6566 so I have closed this ticket as a duplicate. Please watch SERVER-6566 for updates on this issue.

Thanks,
Mark

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