Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
MongoDB Lab: a Single-Node Replica Set in Docker, mongosh, Compass and the Bookstore Data
The right MongoDB setup for development is a password-protected single-node replica set listening on 127.0.0.1; transactions and change streams only work on a replica set, and the member name must resolve from the host. With real output: the compose file and keyfile, rs.initiate, users and roles, mongosh, loading the Bookstore data with mongoimport, connecting from .NET and the transaction error on a standalone server.
CRUD in MongoDB: find, Projection, Update Operators, Upsert and Array Queries
The core of safe CRUD in MongoDB is combining the read, the check and the write in one atomic update: a conditional $inc never takes stock below zero, while read-then-write sells the same stock several times. With real output: orders matched wrongly without $elemMatch, ordered and unordered insertMany, projection, the cost of skip, update operators, positional and filtered positional updates, upsert, findOneAndUpdate, a stock race with 50 concurrent buyers and the replaceOne trap.