MongoDB wire protocol
What is MongoDB wire protocol?
The MongoDB wire protocol is the TCP message format MongoDB's own drivers and mongosh use to talk to a mongod or mongos process, normally on port 27017, documented in MongoDB's own manual rather than an independent spec. AdminKit's guide to checking an exposed MongoDB port explains why an internet-reachable 27017 usually means a deliberately widened bind address.
By AdminKit team, Netbase JSC · Updated
The MongoDB wire protocol is the message format MongoDB’s own drivers and the mongosh shell use to communicate with a mongod or mongos process over TCP, normally on port 27017, which IANA registers for MongoDB. It’s MongoDB-specific rather than a shared database standard, documented directly in MongoDB’s own manual rather than an independent spec body — the same vendor-specific pattern as the MySQL wire protocol. Current drivers send commands as OP_MSG messages: a standard header followed by sections whose body is a single BSON document, the binary JSON-like serialization format MongoDB also uses to store data. Before version 3.6, MongoDB’s binaries bound to all network interfaces with authentication off by default, so a server stood up with no extra configuration spoke this protocol to anyone who could reach it over the network — the exposure a wave of 2017 ransom attacks exploited at scale, wiping tens of thousands of unauthenticated instances. Since 3.6, MongoDB binds to localhost by default, so an internet-reachable port 27017 today usually means an administrator deliberately widened net.bindIp, often without also enabling authentication. Elasticsearch’s HTTP API carried a similar unauthenticated-by-default history before version 8.0, the same kind of insecure default that assumed a trusted network rather than the open internet.
MongoDB wire protocol is part of AdminKit’s machine protocols cluster; the full AdminKit glossary lists other related terms.
Frequently asked questions
What port does the MongoDB wire protocol normally use?
TCP port 27017, the port IANA registers for MongoDB.
Did MongoDB always bind to localhost by default?
No -- before version 3.6, MongoDB bound to all network interfaces with authentication off by default, an exposure a wave of 2017 ransom attacks exploited at scale.
Why would a MongoDB port be reachable from the internet today?
Since 3.6, MongoDB binds to localhost by default, so an internet-reachable port 27017 usually means an administrator deliberately widened net.bindIp, often without also enabling authentication.
Is the MongoDB wire protocol an open, cross-database standard?
No -- it's MongoDB-specific and documented directly in MongoDB's own manual rather than an independent spec body, the same vendor-specific pattern as the MySQL wire protocol.