You pass an array of documents to insertMany. By default, one document in the middle fails a unique index check. What happens?
db.users.insertMany([doc1, doc2_dup, doc3])Read the full question →MongoDB is a document database. Its interviews are about data modelling and index design far more than about query syntax.
Embedding versus referencing, multikey and compound index behaviour, aggregation pipeline stages, read and write concern trade-offs, sharding keys, and replica-set elections.
Where it shows up: Backend roles at document-store shops, analytics pipelines, and teams running Atlas in production.
Twenty real MongoDB questions from the library, code snippet included. Nothing here is paraphrased for search engines. It is the same text a signed-in user sees.
db.users.insertMany([doc1, doc2_dup, doc3])Read the full question →db.col.updateOne({ _id: 1 }, { $pull: { items: { k: 'a' } } })Read the full question →db.people.insertOne({ name: "Ann", age: 30 })
db.people.insertOne({ name: "Bob", city: "NYC", hobbies: ["chess"] })Read the full question →db.logs.deleteMany({})Read the full question →db.users.find({})Read the full question →db.orders.updateOne(
{ status: "pending" },
{ $set: { status: "shipped" } }
)Read the full question →const ObjectId = require("mongodb").ObjectId;
const a = new ObjectId("507f1f77bcf86cd799439011");
const b = new ObjectId("507f1f77bcf86cd799439011");
console.log(a === b);
console.log(a.equals(b));Read the full question →db.col.updateOne(
{ sku: 'A1' },
{ $set: { qty: 10 } },
{ upsert: true }
)Read the full question →db.players.find().sort({ score: -1 }).limit(1)Read the full question →db.users.find({}, { age: 0, city: 0 })Read the full question →db.users.find().limit(5).sort({ age: 1 }).skip(2)Read the full question →db.products.find({ tags: "blue" })Read the full question →db.col.updateOne(
{ _id: 1 },
{ $set: { seen: true }, $setOnInsert: { createdAt: new Date() } },
{ upsert: true }
)Read the full question →db.products.find({ price: { $gt: 100 } })Read the full question →db.users.deleteOne({ email: "missing@example.com" })Read the full question →db.col.updateOne(
{ _id: 1 },
{ $pull: { nums: 2 } }
)Read the full question →db.orders.countDocuments({ status: 'shipped' }, { limit: 5 })Read the full question →db.col.updateOne(
{ _id: 1 },
{ $push: { tags: ["a", "b"] } }
)Read the full question →db.nums.insertMany([
{ _id: 1, v: "a" },
{ _id: 1, v: "b" },
{ _id: 2, v: "c" }
])Read the full question →const result = db.users.find({ active: true });Read the full question →We keep the correct answer, the explanation and the scoring behind sign-in so the platform stays honest, which is why the answer options and the worked explanation for every MongoDB question stay behind a free account. Signing in is free and takes a few seconds.
53 distinct MongoDB topics are tagged across the library. These are the real topic labels stored on the questions, not a hand-written list.
…