Master Nosql MongoDB with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
MongoDB is a NoSQL document-oriented database that stores data in flexible, JSON-like documents called BSON. It is designed for scalability and high performance, making it ideal for applications with rapidly evolving schemas and large volumes of unstructured or semi-structured data.
The document model stores data as documents, which are rich data structures similar to JSON objects. Each document can contain nested fields, arrays, and sub-documents, allowing related data to be stored together rather than spread across multiple tables as in relational databases.
BSON (Binary JSON) is the binary-encoded serialization format MongoDB uses to store documents and make remote procedure calls. It extends JSON with additional data types such as Date, ObjectId, int, long, double, and binary, enabling efficient storage and traversal.
An ObjectId is a 12-byte unique identifier automatically generated by MongoDB as the default _id field for each document. It consists of: A 4-byte timestampA 5-byte random valueA 3-byte incrementing counter ObjectIds are sortable by creation time.
Use db.collection.insertOne() for a single document or db.collection.insertMany() for multiple documents. Example: db.users.insertOne({ name: "Alice", age: 30 }). MongoDB automatically adds an _id field if not provided.
Use db.collection.find(filter, projection) to query documents. Example: db.users.find({ age: { $gt: 25 } }) returns all users older than 25. Use findOne() to return only the first matching document.
MongoDB CRUD operations are: Create: insertOne(), insertMany()Read: find(), findOne()Update: updateOne(), updateMany(), replaceOne()Delete: deleteOne(), deleteMany()
MongoDB provides query operators for filtering: Comparison: $eq, $ne, $gt, $gte, $lt, $lte, $in, $ninLogical: $and, $or, $not, $norElement: $exists, $typeArray: $all, $elemMatch, $size
Use db.collection.updateOne(filter, update) or updateMany(). Update operators include $set (set fields), $unset (remove fields), $inc (increment), $push (add to array), and $pull (remove from array). Example: db.users.updateOne({ name: "Alice" }, { $set: { age: 31 } }).
The aggregation pipeline processes documents through a sequence of stages, each transforming the data. Common stages include $match (filter), $group (aggregate), $project (reshape), $sort, $limit, and $lookup (join). It is MongoDB's primary tool for complex data analysis and transformation.
The $match stage filters documents based on specified conditions, similar to a find() query. It should be placed early in the pipeline to reduce the number of documents processed by subsequent stages. Example: { $match: { status: "active" } }.
The $group stage groups documents by a specified _id expression and applies accumulator operators like $sum, $avg, $min, $max, $push, and $first. Example: { $group: { _id: "$category", total: { $sum: "$price" } } }.
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge