MongoDB Associate Developer study materials
MongoDB Associate Developer study resources

MongoDB Associate Developer: Drivers and Application Development

MongoDB Associate Developer · Work through your exam, one topic at a time.

All guide sections

Drivers and Application Development

Connections

Drivers connect with a URI: mongodb://host:27017/db or mongodb+srv://cluster.example.net/db, which resolves SRV/TXT records for Atlas-style clusters. Build one client per process and reuse it - the client owns a connection pool with maxPoolSize, minPoolSize, and timeouts (serverSelectionTimeoutMS, socketTimeoutMS, connectTimeoutMS). Credentials in a URI must be percent-encoded.

Options that change behavior

retryWrites=true (default in modern drivers) makes single-statement writes safely retryable once after a network error. writeConcern, readConcern, and readPreference can be set on the URI, the client, the database, the collection, or per operation - the most specific wins. Sessions enable causal consistency, transactions, and change streams; change streams require a replica set or sharded cluster and resume with a resumeToken.

Working with results

Queries return a lazy cursor: no round trip happens until you iterate, and the server returns results in batches (batchSize, getMore). Always close or exhaust cursors, otherwise they time out server-side. Drivers generate _id values client-side before the write. BSON types differ from JSON: ObjectId, Decimal128, Date, Binary, Long, Timestamp.

Error handling

Catch driver exceptions and branch on the numeric code - e.g. 11000 for duplicate key, 112 for a write conflict. Retry only idempotent or driver-marked-retryable operations; a non-retryable write error means the operation definitely did not apply.

Worked rule

Configure durability once at the client level (w:majority) and override only where an operation genuinely needs weaker guarantees; scattered per-call overrides are a common source of inconsistent behavior.