MongoDB Developer Associate study materials
MongoDB Developer Associate study resources

MongoDB Developer Associate: Programming Language Specific Questions (C#, Java, Node.js, PHP, Python)

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

All guide sections

Programming Language Specific Questions (C#, Java, Node.js, PHP, Python)

The language-specific domain is delivered in whichever driver track you registered for - C#, Java, Node.js, PHP, or Python. Questions test driver mechanics: client lifecycle and pooling, BSON type mapping, cursor and async patterns, session and transaction helpers, and error handling, using that language's real class names.

Client lifecycle and pooling

MongoClient is thread-safe and expensive to build; create one per process (or per distinct connection string) and share it. Every modern driver pools connections underneath - default maxPoolSize is 100 - so a client per request exhausts sockets and multiplies heartbeats. Keep credentials and options in the URI (mongodb+srv://, authSource, retryWrites=true).

BSON and _id mapping

Drivers surface BSON types directly: ObjectId in Node, org.bson.types.ObjectId in Java, MongoDB.Bson.ObjectId in C#, bson.objectid.ObjectId in PyMongo, MongoDB\BSON\ObjectId in PHP. When an _id crosses a JSON API boundary it becomes a string, and querying with that string silently returns nothing. Convert back first. POJO mapping also differs: C# uses [BsonId]/[BsonElement], Java registers a PojoCodecProvider, Python favours dataclasses, PHP maps to arrays and stdClass.

Cursors, async, errors

Cursors fetch in batches; iterate with await cursor.toArray() or for await in Node, try-with-resources MongoCursor in Java, IAsyncCursor/ToListAsync in C#. Never block on driver async calls with .Result in C# - it deadlocks. Duplicate-key failures surface as code 11000 (DuplicateKeyError, DuplicateKeyException, MongoWriteException), the signal for upsert retry logic.

Sessions and transactions

client.startSession() plus session.withTransaction(cb) is the portable shape: await session.withTransaction(...) in Node, session.withTransaction(...) in Java, session.WithTransactionAsync(...) in C#, session.with_transaction(cb) in PyMongo. The helper retries work labelled TransientTransactionError; hand-rolled start/commit code must do that itself.

Worked example

Node: const {ObjectId} = require('mongodb'); await db.collection('orders').findOne({_id: new ObjectId(req.params.id)}). Passing req.params.id raw returns null, because a 24-hex string never equals an ObjectId. Java: new ObjectId(idString); C#: ObjectId.Parse(idString); Python: ObjectId(id_string); PHP: new MongoDB\BSON\ObjectId($id). The bug looks identical in all five.

Traps

Creating a client per request; storing dates as strings then sorting lexicographically; .Result on async calls; forgetting await on insertOne, so the write is never observed; reaching for the removed PHP mongo extension instead of the mongodb extension plus the mongodb/mongodb library; and reusing an exhausted cursor as if it were a list.