@@ -49,17 +49,18 @@ MongoDB uses the `hello` or `isMaster` commands for handshakes and topology moni
4949preferred command. ` hello ` must always be sent using the ` OP_MSG ` protocol. ` isMaster ` is referred to as "legacy hello"
5050and is maintained for backwards compatibility with servers that do not support the ` hello ` command.
5151
52- If a [ server API version ] ( ../versioned-api/versioned-api.md ) is requested or ` loadBalanced: True ` , drivers MUST use the
53- ` hello ` command for the initial handshake and use the ` OP_MSG ` protocol. If server API version is not requested and
54- ` loadBalanced: False ` , drivers MUST use legacy hello for the first message of the initial handshake with the ` OP_QUERY `
55- protocol (before switching to ` OP_MSG ` if the ` maxWireVersion ` indicates compatibility) , and include ` helloOk:true ` in
56- the handshake request.
52+ Drivers MUST use the ` OP_MSG ` protocol for all handshakes if their minWireVersion is 6 (MongoDB 3.6) or higher. If a
53+ [ server API version ] ( ../versioned-api/versioned-api.md ) is requested or ` loadBalanced: True ` , drivers MUST also use the
54+ ` hello ` command for the initial handshake. If server API version is not requested and ` loadBalanced: False ` , drivers
55+ MUST use legacy hello for the first message of the initial handshake , and include ` helloOk:true ` in the handshake
56+ request.
5757
5858ASIDE: If the legacy handshake response includes ` helloOk: true ` , then subsequent topology monitoring commands MUST use
5959the ` hello ` command. If the legacy handshake response does not include ` helloOk: true ` , then subsequent topology
6060monitoring commands MUST use the legacy hello command. See the
6161[ Server Discovery and Monitoring spec] ( ../server-discovery-and-monitoring/server-discovery-and-monitoring-summary.md )
62- for further information.
62+ for further information. Additionally, note that if the server does not understand ` OP_MSG ` , the server will close the
63+ socket.
6364
6465The initial handshake MUST be performed on every socket to any and all servers upon establishing the connection to
6566MongoDB, including reconnects of dropped connections and newly discovered members of a cluster. It MUST be the first
@@ -80,10 +81,8 @@ conn = Connection()
8081conn.connect() # Connect via TCP / TLS
8182if stable_api_configured or client_options.load_balanced:
8283 cmd = {" hello" : 1 }
83- conn.supports_op_msg = True # Send the initial command via OP_MSG.
8484else :
8585 cmd = {" legacy hello" : 1 , " helloOk" : 1 }
86- conn.supports_op_msg = False # Send the initial command via OP_QUERY.
8786cmd[" backpressure" ] = True
8887cmd[" client" ] = client_metadata
8988if client_options.compressors:
@@ -99,10 +98,6 @@ if creds:
9998
10099reply = conn.send_command(" admin" , cmd)
101100
102- if reply[" maxWireVersion" ] >= 6 :
103- # Use OP_MSG for all future commands, including authentication.
104- conn.supports_op_msg = True
105-
106101# Store the negotiated compressor, see OP_COMPRESSED spec.
107102if reply.get(" compression" ):
108103 conn.compressor = reply[" compression" ][0 ]
@@ -564,6 +559,7 @@ support the `hello` command, the `helloOk: true` argument is ignored and the leg
564559
565560## Changelog
566561
562+ - 2026-06-05: Use OP_MSG for all handshakes.
567563- 2025-09-04: Clarify that drivers do not append the same metadata multiple times.
568564- 2025-06-09: Add requirement to allow appending to client metadata after ` MongoClient ` initialization.
569565- 2024-11-05: Move handshake prose tests from spec file to prose test file.
0 commit comments