[SERVER-37062] db.watch does not show up in autocomplete or help Created: 09/Sep/18  Updated: 29/Oct/23  Resolved: 15/Dec/20

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 4.1.2
Fix Version/s: 4.2.0

Type: Bug Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Backlog - Query Optimization
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
Related
is related to SERVER-34001 Add db.watch() shell helper to open a... Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Query 2019-06-03
Participants:
Linked BF Score: 0

 Description   

In the shell, the autocomplete list for a db object does not include the watch helper.

It looks like the autocomplete function finds properties on an object using Object.keySet, defined here which iterates over enumerable properties.

Object.getOwnPropertyDescriptor shows that the watch property is not enumerable:

Object.getOwnPropertyDescriptor(db, "watch")
{
	"value" : function (pipeline, options) {
        pipeline = pipeline || [];
        options = options || {};
        assert(pipeline instanceof Array, "'pipeline' argument must be an array");
        assert(options instanceof Object, "'options' argument must be an object");
 
        let changeStreamStage = {fullDocument: options.fullDocument || "default"};
        delete options.fullDocument;
 
        if (options.hasOwnProperty("resumeAfter")) {
            changeStreamStage.resumeAfter = options.resumeAfter;
            delete options.resumeAfter;
        }
 
        if (options.hasOwnProperty("startAtOperationTime")) {
            changeStreamStage.startAtOperationTime = options.startAtOperationTime;
            delete options.startAtOperationTime;
        }
 
        pipeline.unshift({$changeStream: changeStreamStage});
        return this._runAggregate({aggregate: 1, pipeline: pipeline}, options);
    },
	"writable" : true,
	"enumerable" : false,
	"configurable" : true
}

But I'm not sure why watch is not enumerable while other similarly defined properties like getFreeMonitoringStatus are.

Additionally, db.watch does not show up in the output of db.help().



 Comments   
Comment by Githook User [ 10/Dec/19 ]

Author:

{'email': 'charlie.swanson@mongodb.com', 'name': 'Charlie Swanson', 'username': 'cswanson310'}

Message: Revert "SERVER-37062 db.watch does not show up in autocomplete or help"

This reverts commit b7a300db322cad07c305f287d1f06540c783a313.
Branch: v4.0
https://github.com/mongodb/mongo/commit/711b443933b323f7cb9c9fa4256a37a777bf58e2

Comment by Githook User [ 09/Dec/19 ]

Author:

{'name': 'Charlie Swanson', 'username': 'cswanson310', 'email': 'charlie.swanson@mongodb.com'}

Message: SERVER-37062 db.watch does not show up in autocomplete or help

(cherry picked from commit b85b159f44e155ea05b456552a1cd5782a7d7850)
Branch: v4.0
https://github.com/mongodb/mongo/commit/b7a300db322cad07c305f287d1f06540c783a313

Comment by Githook User [ 30/May/19 ]

Author:

{'name': 'Davis Haupt', 'email': 'davis.haupt@mongodb.com', 'username': 'davish'}

Message: SERVER-37062 db.watch does not show up in autocomplete or help
Branch: master
https://github.com/mongodb/mongo/commit/b85b159f44e155ea05b456552a1cd5782a7d7850

Comment by Davis Haupt (Inactive) [ 29/May/19 ]

Seems like the issue with watch not showing up in autocomplete (i.e. not being returned in the call to keySet) was related to the fact that watch() used to be a deprecated method on prototype as well (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch). Properties inherited from Object aren't enumerable unless explicitly made so, so watch() was left out of autocomplete. On the newest version of the JS engine being used by the shell that was updated in this commit, Object.prototype.watch() has been removed, and so the watch is enumerable.

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