Refactor CommandMessage to replace namespace with database name

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Unknown
    • 5.6.0
    • Affects Version/s: None
    • Component/s: Internal
    • None
    • Fully Compatible
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      There is some confusing code that remains from the pre-OP_MSG wire protocol implementation.

      In CommandProtocolImpl a MongoNamespace instance is constructed from the provided database name and MongoNamespace#COMMAND_COLLECTION_NAME, whose value is "$cmd". The namespace is than passed to CommandMessage, and subsequently only the database part is used:

              extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName())));
      

      All this is unnecessary and is a remnant of the old pre-OP_MSG wire protocol, which requres a synthetic collection name for commands that don't actually operate on a collection, e.g. ping is executed on the namespace admin.$cmd. With the new wire protocol, the collection name, if necessary, is typically the value of the first field in the command, e.g. {{ find: <coll name> }}, and omitted for commands that don't operate on a collection.

      To make the code more understandable, the namespace should just be replaced with the database name, and the synthetic collection name should be removed. Note that currently there is a very confusing method on RequestMessage, getCollectionName, but it doesn't return the collection name you might think it does. It's always <db name>.$cmd.

              Assignee:
              Jeffrey Yemin
              Reporter:
              Jeffrey Yemin
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: