What is the MongoDB wire protocol?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex MongoDB topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
The MongoDB Wire Protocol is the binary protocol used for communication between MongoDB clients (drivers) and the MongoDB server over TCP. It defines the message format for all database operations. Key aspects: (1) TCP-based: runs over standard TCP (default port 27017); (2) OP_MSG: the current primary message format (replaced older OP_QUERY, OP_INSERT, etc. in MongoDB 3.6). Uses BSON documents for both request and response; (3) Message structure: header (length, requestId, responseTo, opCode) + body (BSON document with operation details); (4) Compression: wire protocol supports zlib, Snappy, and zstd compression to reduce network bandwidth; (5) Authentication: SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, GSSAPI (Kerberos), PLAIN (LDAP) authentication mechanisms; (6) TLS/SSL: optional encryption of the wire protocol for security. MongoDB drivers: handle the wire protocol for you — you never interact with it directly. Drivers exist for all major languages: Node.js, Python (PyMongo), Java (MongoDB Java Driver), Go, C#, PHP, Ruby, Rust, etc. Connection pooling: drivers maintain connection pools to MongoDB — multiple socket connections to the server, reused across requests. Pool size is configurable (default: 100 per MongoClient). Create ONE MongoClient per application and reuse it — don't create/destroy per request.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last MongoDB project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is a sparse index in MongoDB?
Next
What is a compound index and when should you use it?