[SERVER-28397] shell helper for update must pass through all options Created: 20/Mar/17  Updated: 06/Dec/22

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

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 1
Labels: former-quick-wins, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-39975 update accepts true or an options doc... Closed
Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

The helper for update expects and looks for options multi and upsert (also writeConcern and collation, and then as of 3.5.9 arrayFilters) and it silently ignores any and all other options.

This is bad because (a) misspelled options are silently ignored and the wrong thing happens (b) if we add new options in the future, they will also be silently ignored and not sent ahead to the server by older shell.



 Comments   
Comment by Ian Whalen (Inactive) [ 24/Aug/18 ]

Considered this for a quick win but leaving back on the backlog because it isn't quite as easy as it sounds like it would be, and the priority here is really only low to medium.

Comment by Asya Kamsky [ 16/Aug/17 ]

It passes through writeConcern and collation - when we have added a new option, we've had to remember to update the helper, but it means that an older shell version will silently swallow any option it doesn't understand (rather than passing it to server).

db.books._parseUpdate
function (query, obj, upsert, multi) {
    if (!query)
        throw Error("need a query");
    if (!obj)
        throw Error("need an object");
 
    var wc = undefined;
    var collation = undefined;
    var arrayFilters = undefined;
    // can pass options via object for improved readability
    if (typeof(upsert) === "object") {
        if (multi) {
            throw Error("Fourth argument must be empty when specifying " +
                        "upsert and multi with an object.");
        }
 
        var opts = upsert;
        multi = opts.multi;
        wc = opts.writeConcern;
        upsert = opts.upsert;
        collation = opts.collation;
        arrayFilters = opts.arrayFilters;
    }
 
    // Normalize 'upsert' and 'multi' to booleans.
    upsert = upsert ? true : false;
    multi = multi ? true : false;
 
    if (!wc) {
        wc = this.getWriteConcern();
    }
 
    return {
        "query": query,
        "obj": obj,
        "upsert": upsert,
        "multi": multi,
        "wc": wc,
        "collation": collation,
        "arrayFilters": arrayFilters
    };
}

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