MongoDB Developer Associate study materials
MongoDB Developer Associate study resources

MongoDB Developer Associate cheat sheet

MongoDB Developer Associate · Keep the key ideas within reach.

Quick reference

Core MongoDB Functionality

  • The _id field is mandatory in every document; if omitted, the driver generates an ObjectId. A unique index on _id is created automatically and cannot be dropped.

  • BSON document size limit is 16 MB; use GridFS for larger binary data. A collection namespace limit also applies to database and collection name lengths.

  • Embedding favors one-to-few read-together data; referencing favors one-to-many, many-to-many, and unbounded arrays. Arrays that grow without limit risk the 16 MB document cap.

  • Query operators: $eq, $gt, $gte, $lt, $lte, $ne, $in, $nin, $exists, $type, $regex, $elemMatch. Use $elemMatch when multiple conditions must match the same array element.

  • Aggregation pipeline stages run in order: $match, $project, $group, $sort, $limit, $lookup, $unwind, $facet, $addFields. $match and $sort early exploit indexes.

  • Index types: single field, compound (ESR rule: Equality, Sort, Range), multikey (array field), text, geospatial (2dsphere), hashed, wildcard, partial, sparse, TTL, and unique.

  • Compound index prefix rule: an index on {a:1,b:1,c:1} supports queries on a, a+b, and a+b+c, but not b alone or b+c.

  • Write concern w:1 acknowledges after primary write; w:majority waits for majority of voting members. Read concern levels: local, available, majority, linearizable, snapshot.

  • Transactions require a replica set or sharded cluster (not standalone), have a 60-second default lifetime, and each operation must specify read/write concern at transaction start.

Quick reference

Programming Language Specific Questions

  • Node.js: MongoClient is the entry point; call client.connect() once and reuse the client. Db and Collection objects are lightweight and can be re-created freely.

  • Node.js: use await collection.insertOne(doc) which returns {acknowledged, insertedId}; insertMany returns insertedIds. Cursor iteration uses for await (const doc of cursor).

  • Node.js: ObjectId is imported from 'mongodb' (BSON); new ObjectId(string) throws on invalid hex. Use EJSON for lossless serialization of BSON types.

  • Java: use com.mongodb.client.MongoClients.create(connectionString); documents are org.bson.Document. Filters and Updates are static factory helpers (Filters.eq, Updates.set).

  • Java: POJO mapping requires a codec registry (PojoCodecProvider) and @BsonId / @BsonProperty annotations; the driver's default codec registry must be combined with it.

  • C#: use MongoClient from MongoDB.Driver; IMongoCollection is typed. Builders.Filter and Builders.Update construct filters/updates; async methods end in Async.

  • Python (PyMongo): MongoClient('mongodb://...'); db = client.dbname; coll = db.collname. insert_one returns InsertOneResult with inserted_id. Use bson.ObjectId for ids.

  • PHP: MongoDB\Driver\Manager is the low-level extension; MongoDB\Client\Collection (mongodb/mongodb library) offers findOneAndUpdate, aggregate, and bulkWrite with filter/update arrays.

  • Language-agnostic: always pass the connection string via environment variable; enable retryWrites=true (default in modern drivers) which retries retryable writes exactly once on network errors.