Pick a topic — languages & databases — 100+ questions and answers in the center column.
MongoDB
Documents, aggregation, replica sets, sharding.
102 questions
Question 1
Document-oriented NoSQL database storing BSON JSON-like documents in collections. Horizontally scalable via sharding, high availability via replica sets; popular for flexible schema and rapid iteration.
Example code
db.runCommand({ ping: 1 })Question 2
Documents are nested maps/arrays—embed vs reference models trade query locality vs update isolation.
Example code
db.users.insertOne({ name: "Ada", tags: ["dev"] })Question 3
Binary JSON superset with extra types (ObjectId, Decimal128, Date)—efficient encoding and traversal on wire and disk.
Example code
ObjectId()Question 4
12-byte value: timestamp + random + counter—roughly sortable by creation time; not guaranteed monotonic under load.
Example code
db.coll.find({ _id: ObjectId("507f1f77bcf86cd799439011") })Question 5
Database contains collections; collections contain documents—no rigid schema but indexes enforce access patterns.
Example code
db.coll.insertOne({})Question 6
Required unique key per document; auto-generated ObjectId if omitted—shard key consideration in clusters.
Example code
db.coll.find({ age: { $gt: 21 } })Question 7
insertOne/Many, find with filter, update with operators, replaceOne, delete—operations are atomic per document.
Example code
db.coll.updateOne({ _id: 1 }, { $set: { x: 1 } })Question 8
$gt, $in, $regex, $elemMatch, $exists—compose in filter objects for rich predicates.
Example code
db.coll.aggregate([{ $match: { a: 1 } }, { $group: { _id: "$b", c: { $sum: 1 } } }])Question 9
$set, $inc, $push, $pull, $unset—field-level updates without full document replace.
Example code
db.orders.aggregate([{ $lookup: { from: "items", localField: "_id", foreignField: "orderId", as: "items" } }])Question 10
Stages ($match, $group, $lookup, $project) process documents in sequence—push filters early for performance.
Example code
db.coll.createIndex({ a: 1, b: -1 })Question 11
Left outer join to another collection—can be heavy; denormalize when read-heavy.
Example code
db.coll.find({ a: 1 }, { _id: 0, a: 1 })Question 12
Single/compound, multikey on arrays, text, geospatial, wildcard—explain() plans like SQL EXPLAIN.
Example code
rs.status()Question 13
When projection includes only indexed fields and index can satisfy query—no document fetch.
Example code
rs.conf()Question 14
Primary + secondaries; automatic failover; read concern/read preference tune staleness vs scale-out reads.
Example code
{ w: "majority", j: true }Question 15
Majority elects new primary if old dies—arbiter nodes vote without data (use sparingly).
Example code
"majority"Question 16
Ack levels w: majority vs w:1—durability vs latency; journal sync options.
Example code
session.startTransaction()Question 17
local, majority, linearizable—balance monotonic reads and causal consistency features.
Example code
sh.status()Question 18
Multi-document ACID since 4.0 in replica sets; sharded transactions later—higher overhead than single-doc ops.
Example code
sh.splitFind("test.users", { _id: 50 })Question 19
Shard key choice is critical—hot shards from poorly chosen keys; zone sharding for geo or tenant isolation.
Example code
mongos --configdb cfg/...Question 20
Balancer moves chunks between shards—impacts load; jumbo chunks block balance until split.
Example code
db.coll.watch([{ $match: { operationType: "insert" } }])Question 21
Router for sharded cluster—stateless; config servers hold metadata; add more for router throughput.
Example code
db.createCollection("c", { validator: { $jsonSchema: { bsonType: "object" } } })Question 22
Tail oplog-backed change feed—resume tokens for exactly-once style consumers at app level.
Example code
db.coll.createIndex({ t: 1 }, { expireAfterSeconds: 3600 })Question 23
$jsonSchema in validator—optional structure enforcement without losing document model.
Example code
db.coll.find({ $text: { $search: "mongo" } })Question 24
Expire documents after a Date field + offset—background removal, not precise to the second.
Example code
bucket.files.find()Question 25
$text with text index—basic BM25 scoring; Atlas Search richer for production search UX.
Example code
mongodb+srv://user:pass@cluster.mongodb.net/dbQuestion 26
Chunk large files across documents—driver API; object storage often simpler for blobs.
Example code
db.coll.find().explain("executionStats")Question 27
mongodb[+srv]://user:pass@hosts/db?options—TLS, retryWrites, readPreference query params.
Example code
db.serverStatus().wiredTiger.cacheQuestion 28
GUI vs shell—both issue same commands; scripts often use mongosh --file.
Example code
db.serverStatus().wiredTigerQuestion 29
Winning plan, docs examined vs returned—high examination ratio signals missing/wrong index.
Example code
db.getSiblingDB("local").oplog.rs.find().limit(1)Question 30
WiredTiger cache (formerly majority of RAM)—OS file cache also helps; monitor resident vs mapped.
Example code
mongodump --uri="mongodb://localhost"Question 31
Default storage engine—document-level concurrency, compression, checkpoints.
Example code
db.createUser({ user: "app", pwd: "x", roles: ["readWrite"] })Question 32
Capped replication log—size affects replica catch-up window; too small risks full resync.
Example code
db.coll.aggregate([{ $group: { _id: "$x", n: { $sum: 1 } } }], { allowDiskUse: true })Question 33
mongodump logical; filesystem snapshots for consistent physical; Atlas continuous backup managed.
Example code
// max document 16MB BSONQuestion 34
Auth + TLS, least-privilege roles, network binding, field-level encryption for sensitive paths.
Example code
// prefer SQL/relational when heavy cross-row constraintsQuestion 35
Built-in roles + custom—database and collection granularity; test with application user.
Example code
db.stats()Question 36
Large sorts/group stages spill to disk—slower but avoids memory cap failures.
Example code
db.coll.deleteMany({ status: "draft" })Question 37
16MB max document—design splits or GridFS for larger payloads.
Example code
db.coll.replaceOne({ _id: 1 }, { _id: 1, name: "new" })Question 38
Heavy multi-row ACID across many entities, strong relational constraints, or team lacks operational maturity for clusters.
Example code
db.adminCommand({ listDatabases: 1 })Question 39
Managed MongoDB—automated backups, scaling UI, global clusters; vendor lock tradeoffs.
Example code
// MongoDB: Atlas
db.runCommand({ ping: 1 })Question 40
Shared tier vs dedicated cluster—noisy neighbor vs predictable performance.
Example code
// MongoDB: M10 vs dedicated
db.runCommand({ ping: 1 })Question 41
Private networking to app tier—security over public internet with allowlists.
Example code
// MongoDB: VPC peering Atlas
db.runCommand({ ping: 1 })Question 42
Cloud provider private link—tightest network path to Atlas.
Example code
// MongoDB: Private Endpoint
db.runCommand({ ping: 1 })Question 43
Enterprise automation—monitoring, backup, automation agents.
Example code
// MongoDB: Ops Manager / Cloud Manager
db.runCommand({ ping: 1 })Question 44
Live server stats—throughput and hot collections quick view.
Example code
// MongoDB: mongostat / mongotop
db.runCommand({ ping: 1 })Question 45
Slow op logging—watch overhead; use sampling in prod.
Example code
// MongoDB: profiler
db.runCommand({ ping: 1 })Question 46
Inspect and terminate long operations—care with replication implications.
Example code
// MongoDB: currentOp / killOp
db.runCommand({ ping: 1 })Question 47
Filter by secs_running, ns—find stuck aggregations.
Example code
// MongoDB: db.currentOp
db.runCommand({ ping: 1 })Question 48
Foreground vs background (deprecated patterns)—modern builds online with constraints per version.
Example code
// MongoDB: index builds
db.runCommand({ ping: 1 })Question 49
Sparse targeted indexes—smaller and faster for filtered queries.
Example code
// MongoDB: partialFilterExpression
db.runCommand({ ping: 1 })Question 50
Locale-aware sort/compare—index must match collation for efficient plans.
Example code
// MongoDB: collation
db.runCommand({ ping: 1 })Question 51
Collation strength 2—email login style lookups.
Example code
// MongoDB: case insensitive index
db.runCommand({ ping: 1 })Question 52
Index arbitrary subfields—flexible schema cost: larger index.
Example code
// MongoDB: wildcard index
db.runCommand({ ping: 1 })Question 53
Test drop impact without removing—hide from planner temporarily.
Example code
// MongoDB: hidden index
db.runCommand({ ping: 1 })Question 54
Force plan—last resort; planner changes version to version.
Example code
// MongoDB: hint()
db.runCommand({ ping: 1 })Question 55
Plans cached per shape—clear with planCacheClear after index changes.
Example code
// MongoDB: plan cache
db.runCommand({ ping: 1 })Question 56
Multiple aggregation pipelines in parallel—dashboard style multi-bucket reports.
Example code
// MongoDB: facet stage
db.runCommand({ ping: 1 })Question 57
Time-series grouping into pre-aggregated buckets—reduce document count.
Example code
// MongoDB: bucket pattern
db.runCommand({ ping: 1 })Question 58
$out writes collection; $merge upserts—ETL patterns inside Mongo.
Example code
// MongoDB: out merge stages
db.runCommand({ ping: 1 })Question 59
Recursive traversal—limited depth; graph DBs better for deep graphs.
Example code
// MongoDB: graphLookup
db.runCommand({ ping: 1 })Question 60
Combine collections in pipeline—analytics across heterogeneous sources.
Example code
// MongoDB: unionWith
db.runCommand({ ping: 1 })Question 61
Gap filling for charts—time series collection helpers.
Example code
// MongoDB: densify / fill (time series)
db.runCommand({ ping: 1 })Question 62
Optimized storage for metrics—metaField and timeField schema.
Example code
// MongoDB: time series collections
db.runCommand({ ping: 1 })Question 63
Aggregation expressions inside find—powerful but cannot use all index paths.
Example code
// MongoDB: $expr
db.runCommand({ ping: 1 })Question 64
Spill to disk for large pipelines—set when memory errors occur.
Example code
// MongoDB: aggregation allowDiskUse
db.runCommand({ ping: 1 })Question 65
Scale reads—eventual consistency; hedge reads optional.
Example code
// MongoDB: read preference secondary
db.runCommand({ ping: 1 })Question 66
Lowest latency member—good for global apps with local secondaries.
Example code
// MongoDB: read preference nearest
db.runCommand({ ping: 1 })Question 67
Target reads to specific data centers—operational control.
Example code
// MongoDB: tags in replica sets
db.runCommand({ ping: 1 })Question 68
Idempotent writes with retryWrites—duplicate key handling in app.
Example code
// MongoDB: write retryability
db.runCommand({ ping: 1 })Question 69
Atomic single-doc read-update—compare with transactions overhead.
Example code
// MongoDB: findAndModify
db.runCommand({ ping: 1 })Question 70
Ordered vs unordered batches—throughput vs error stop semantics.
Example code
// MongoDB: bulkWrite
db.runCommand({ ping: 1 })Question 71
Stop on first error—unordered continues for independent docs.
Example code
// MongoDB: ordered inserts
db.runCommand({ ping: 1 })Question 72
Transactions abort on conflict—exponential backoff in app.
Example code
// MongoDB: write conflict retry
db.runCommand({ ping: 1 })Question 73
Multi-doc consistent reads in transactions—compatibility matrix per version.
Example code
// MongoDB: snapshot read concern
db.runCommand({ ping: 1 })Question 74
Session token ties reads after writes—driver session APIs.
Example code
// MongoDB: causal consistency
db.runCommand({ ping: 1 })Question 75
Strongest single-doc read—primary only and after write majority.
Example code
// MongoDB: linearizable reads
db.runCommand({ ping: 1 })Question 76
Hashed shard key spreads writes—loses range query locality.
Example code
// MongoDB: shard key hashed
db.runCommand({ ping: 1 })Question 77
Compound range keys—risk hot shard on monotonic inserts (e.g., time only).
Example code
// MongoDB: shard key range
db.runCommand({ ping: 1 })Question 78
Add suffix to shard key to split jumbo—planning migration carefully.
Example code
// MongoDB: refineCollectionShardKey
db.runCommand({ ping: 1 })Question 79
Pin ranges to regions—data residency compliance patterns.
Example code
// MongoDB: zone sharding
db.runCommand({ ping: 1 })Question 80
Schedule balancing off-peak—throttle impact.
Example code
// MongoDB: moveChunk / balancer window
db.runCommand({ ping: 1 })Question 81
Replica set holding chunk metadata—critical SPOF class; always HA.
Example code
// MongoDB: config servers
db.runCommand({ ping: 1 })Question 82
Metadata refresh—stale router rare issues after sudden moves.
Example code
// MongoDB: mongos caching
db.runCommand({ ping: 1 })Question 83
Online shard key change (newer versions)—heavy operation; read docs.
Example code
// MongoDB: reshardCollection
db.runCommand({ ping: 1 })Question 84
Client-side encrypted fields with server-side queries—driver and version requirements.
Example code
// MongoDB: Queryable Encryption
db.runCommand({ ping: 1 })Question 85
App encrypts selected fields—server never sees plaintext.
Example code
// MongoDB: Client-Side Field Level Encryption
db.runCommand({ ping: 1 })Question 86
Enterprise auth integrations—Ops/Atlas configuration.
Example code
// MongoDB: LDAP/Kerberos
db.runCommand({ ping: 1 })Question 87
Log DDL/DML to syslog/files—compliance; volume planning.
Example code
// MongoDB: Auditing
db.runCommand({ ping: 1 })Question 88
Key management integration—enterprise encryption at rest stories.
Example code
// MongoDB: KMIP
db.runCommand({ ping: 1 })Question 89
Size per process * pod count—avoid overwhelming mongos/mongod.
Example code
// MongoDB: driver connection pools
db.runCommand({ ping: 1 })Question 90
Fail fast when no suitable member—tune for cloud blips.
Example code
// MongoDB: ServerSelectionTimeout
db.runCommand({ ping: 1 })Question 91
DNS seed list—SRV + TXT for TLS and replica set discovery.
Example code
// MongoDB: SRV connection string
db.runCommand({ ping: 1 })Question 92
Stateful volume for /data/db—ulimits and transparent huge pages Linux tuning.
Example code
// MongoDB: Docker mongodb
db.runCommand({ ping: 1 })Question 93
Percona/MongoDB operators—StatefulSet patterns for replica sets.
Example code
// MongoDB: Kubernetes operator
db.runCommand({ ping: 1 })Question 94
Per-collection lock and time stats—pair with mongostat.
Example code
// MongoDB: mongotop
db.runCommand({ ping: 1 })Question 95
Replay captured traffic—capacity testing tool.
Example code
// MongoDB: mongoreplay
db.runCommand({ ping: 1 })Question 96
isMaster/hello for load balancers—driver compatibility with hello ok.
Example code
// MongoDB: HTTP health check
db.runCommand({ ping: 1 })Question 97
Cap connections at mongod—align with load balancer limits.
Example code
// MongoDB: maxIncomingConnections
db.runCommand({ ping: 1 })Question 98
Runtime tunables—use cautiously in prod with change management.
Example code
// MongoDB: setParameter
db.runCommand({ ping: 1 })Question 99
WiredTiger + glibc allocator interactions—Linux hugepages guidance in docs.
Example code
// MongoDB: tcmalloc tuning
db.runCommand({ ping: 1 })Question 100
Capture subset of ops for support—privacy scrub fields.
Example code
// MongoDB: traffic recording
db.runCommand({ ping: 1 })Question 101
Replica full data copy—bandwidth and oplog window must suffice.
Example code
// MongoDB: initial sync
db.runCommand({ ping: 1 })Question 102
Secondary that never becomes primary—analytics or DR-only nodes.
Example code
// MongoDB: priority 0 member
db.runCommand({ ping: 1 })