MongoDB Protocol Guide
Complete reference for CRUD, Aggregations, Transactions, Change Streams, and Schema Validation.
Supported MongoDB Capabilities
KOLMOS provides a production-ready MongoDB wire server supporting BSON OP_MSG protocol version 4.0+. Supported capabilities include: - **CRUD Operations:** `insert`, `find`, `update`, `delete`, `findAndModify`, `bulkWrite`, `countDocuments`, `distinct`. - **ACID Transactions:** `startTransaction`, `commitTransaction`, `abortTransaction` with read-your-own-writes memory buffering & rollback. - **Change Streams:** `watch()`, `$changeStream` with real-time `CHANGE_LOG` publisher and resume tokens. - **Capped Collections:** Fixed-size FIFO auto-eviction (`size`, `max`) and delete restrictions. - **Schema Validation:** Recursive BSON Draft 4 `$jsonSchema` validator (`validationLevel`, `validationAction`). - **TTL Indexes:** Background cleanup worker (`expireAfterSeconds`) running automatic document purges.
Aggregation Pipeline Stages
Over 35 aggregation pipeline stages are fully supported:
db.orders.aggregate([
// 1. Filter matching documents
{ $match: { status: "completed" } },
// 2. Left-outer join across collections
{
$lookup: {
from: "users",
localField: "userId",
foreignField: "_id",
as: "userInfo"
}
},
{ $unwind: "$userInfo" },
// 3. Group and aggregate
{
$group: {
_id: "$userInfo.country",
totalRevenue: { $sum: "$amount" },
avgOrderSize: { $avg: "$amount" },
count: { $sum: 1 }
}
},
// 4. Window functions
{
$setWindowFields: {
sortBy: { totalRevenue: -1 },
output: {
rank: { $rank: {} }
}
}
},
// 5. Pagination
{ $sort: { totalRevenue: -1 } },
{ $limit: 10 }
]);Geospatial Queries
Full 2dsphere spherical geometry support using exact Haversine distance and ray-casting point-in-polygon math:
// 1. Insert GeoJSON Point
db.places.insertOne({
name: "Central Park",
loc: { type: "Point", coordinates: [-73.96, 40.78] }
});
// 2. $near Proximity Search
db.places.find({
loc: {
$near: {
$geometry: { type: "Point", coordinates: [-73.96, 40.78] },
$maxDistance: 5000 // 5 km radius
}
}
});
// 3. $geoWithin Polygon Search
db.places.find({
loc: {
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [[
[-74.0, 40.7],
[-73.9, 40.7],
[-73.9, 40.8],
[-74.0, 40.8],
[-74.0, 40.7]
]]
}
}
}
});