MongoDB Developer Associate study materials
MongoDB Developer Associate study resources

MongoDB Developer Associate flashcards

MongoDB Developer Associate · Build recall with a focused review session.

32 cards. Read the term and the definition here. The deck at the top of this page is optional.

_id field
Every MongoDB document requires an _id field. If the application omits it, the driver generates an ObjectId. A unique index on _id is created automatically and cannot be dropped.
BSON document size limit
A single BSON document cannot exceed 16 megabytes. For larger binary objects, use GridFS, which splits data across chunks stored in two collections.
Embedding vs referencing
Embed when related data is read together and bounded in size. Reference when arrays could grow unbounded, when data is shared, or when documents would approach the 16 MB limit.
$elemMatch operator
Matches documents where at least one array element satisfies all specified conditions. Without it, separate conditions can match different elements of the same array, giving incorrect results.
ESR rule
For compound indexes, order keys as Equality fields first, then Sort fields, then Range fields. This lets the index serve filter, sort, and range stages without an in-memory sort.
Compound index prefix rule
An index on {a:1,b:1,c:1} supports queries on a, on a+b, and on a+b+c. It does not support queries on b alone or b+c, because those skip the leading prefix.
Multikey index
An index on a field containing an array creates one index entry per array element. Multikey indexes cannot cover queries that filter on the array field itself.
TTL index
A single-field index with expireAfterSeconds deletes documents after the specified time. The background task runs roughly every 60 seconds, so deletion is not immediate.
Write concern majority
w:majority acknowledges a write after it is applied to a majority of voting replica set members. It protects against rollback if the primary fails immediately after acknowledging.
Read concern levels
local reads the node's latest data; majority reads data acknowledged by a majority; linearizable guarantees no stale reads; snapshot provides a consistent point-in-time view for transactions.
Aggregation $lookup
Performs a left outer join to another collection in the same database, adding an array field of matching documents. Use pipeline form for correlated subqueries with conditions.
Aggregation $unwind
Deconstructs an array field, outputting one document per element. Use preserveNullAndEmptyArrays to keep documents where the array is missing, null, or empty.
$facet stage
Runs multiple aggregation pipelines on the same input documents and outputs a single document with one array field per sub-pipeline. Commonly used for paginated results with total counts.
Transactions requirements
Multi-document transactions require a replica set or sharded cluster, not a standalone server. They default to a 60-second lifetime and must specify read and write concern at start.
Retryable writes
With retryWrites=true (default in modern drivers), the driver retries certain network-failure writes exactly once. It requires a replica set or sharded cluster, not a standalone.
Upsert behavior
updateOne with upsert:true inserts a new document if no match exists. The new document is built from the filter's equality conditions plus the update operators.
Node.js MongoClient reuse
Create one MongoClient per process and reuse it. Db and Collection objects are lightweight handles that can be re-created per request without opening new connections.
Node.js insertOne result
await collection.insertOne(doc) resolves to an InsertOneResult containing acknowledged and insertedId. insertMany resolves to insertedIds, a map keyed by document index.
Node.js cursor iteration
Use for await (const doc of collection.find(filter)) to iterate a cursor. Calling toArray() loads all results into memory; use limit and batchSize for large result sets.
Node.js ObjectId import
Import ObjectId from the 'mongodb' package (re-exported from bson). new ObjectId(hexString) throws if the string is not a valid 24-character hex value.
Java MongoClients factory
com.mongodb.client.MongoClients.create(connectionString) returns a MongoClient. Documents are org.bson.Document; build queries with Filters and Updates static helper classes.
Java POJO codec registry
Map POJOs by registering a PojoCodecProvider and combining it with the default codec registry. Annotate the id field with @BsonId and map names with @BsonProperty.
Java aggregation helper
Use collection.aggregate(List.of(Aggregates.match(...), Aggregates.group(...))) with Aggregates static factories. Results return as Document or mapped POJOs via the codec registry.
C# Builders filter
Builders<T>.Filter.Eq and Builders<T>.Update.Set compose typed filters and updates. Combine filters with the & operator or Filter.And for multiple conditions.
C# async driver methods
MongoDB.Driver exposes async variants such as InsertOneAsync, FindAsync, and UpdateOneAsync. Await them to avoid blocking threads in ASP.NET request pipelines.
Python PyMongo insert_one
collection.insert_one(doc) returns InsertOneResult whose inserted_id attribute holds the generated ObjectId. insert_many returns InsertManyResult with inserted_ids.
Python PyMongo connection
MongoClient(uri) is lazy; it connects on first operation. Access databases and collections with attribute or bracket syntax: client.dbname.collname.
PHP MongoDB Manager
MongoDB\Driver\Manager is the low-level extension handling connections and commands. The mongodb/mongodb library wraps it with MongoDB\Client\Collection for convenience methods.
PHP bulkWrite usage
Collection::bulkWrite takes an array of operations like ['insertOne' => [['x'=>1]]] or ['updateOne' => [['filter'=>..., 'update'=>...]]]. Runs them in a single round trip.
Connection string environment variable
Store the MongoDB URI in an environment variable rather than source code. Modern drivers read it once at client creation and enable retryWrites by default.
Driver index creation
Call collection.createIndex(keys, options) at startup for idempotent index setup. Options include unique, sparse, expireAfterSeconds, partialFilterExpression, and background.
Driver error handling
Catch driver-specific exceptions like MongoWriteException, MongoDuplicateKeyException, and MongoTimeoutException. Inspect the error code to distinguish duplicate key (11000) from other failures.