@volter/twin-mongodb
v0.1.37
Published
Local MongoDB twin: the MongoDB wire protocol (OP_MSG and the OP_QUERY handshake) served from the World state kernel, so an unmodified mongodb driver or mongoose app runs with nothing installed and no container.
Readme
@volter/twin-mongodb
A MongoDB server for a World: the MongoDB wire protocol on a loopback TCP listener, over the World
state kernel. An unmodified application using the official mongodb driver or mongoose connects to
mongodb://127.0.0.1:<port>/<db> as to a standalone MongoDB 7.0, with nothing installed and no
container.
How a World gets it
A repository whose env names a MongoDB connection string (MONGO_URI, MONGODB_URL, a
mongodb:// DATABASE_URL) is managed infrastructure: volter-world init declares the
infrastructure service and points the variable at it. On a machine with a container runtime that
service runs mongo:7; without one, volter-world-infra serves the mongodb kind with this package,
its state under the World's data directory, so it survives down and up.
Run it alone with world-mongodb serve --port 27017 --root <dir>.
Where the state lives
In the kernel, one subject per stored thing: collection (<db>.<name>), index
(<db>.<name>#<index>) and document (<db>.<name>/<_id>, the document as canonical Extended JSON).
One command is one kernel entry. Checkpoints, branches, push and history work as for any twin.
Coverage
The denominator is MongoDB's command reference
(171 commands) plus the semantics the answers depend on; src/mongodb-capabilities.ts is the
manifest, every entry done or todo.
- Commands done:
hello,isMaster,ping,buildInfo,getParameter,connectionStatus,whatsmyuri,dbStats,listDatabases,listCollections,create,drop,dropDatabase,insert,find,getMore,killCursors,update,delete,findAndModify,count,distinct,aggregate,createIndexes,listIndexes,dropIndexes,startSession,endSessions,refreshSessions,killSessions,killAllSessions. - Every other command answers MongoDB's
no such command: '<name>'(59 CommandNotFound). - Queries:
$eq $ne $gt $gte $lt $lte $in $nin $exists $regex $and $or $nor $not $elemMatch $size $all $type $mod $expr, dotted paths through embedded documents and arrays.$text,$where,$jsonSchema, geo and bitwise operators are todo. - Updates:
$set $unset $inc $mul $min $max $rename $push(with$each $position $sort $slice)$addToSet $pull $pullAll $pop $setOnInsert $currentDate $bit, positional$,$[],$[<id>]witharrayFilters, replacement and pipeline updates, upserts. - Aggregation:
$match $project $addFields $set $unset $sort $limit $skip $count $group $sortByCount $unwind $lookup $replaceRoot $replaceWith $facetand the common expressions and accumulators.$out $merge $unionWith $bucket $sample $graphLookupand the rest answer CommandNotSupported (115). - Indexes: unique enforcement with
E11000 duplicate key error(keyPattern, keyValue) on insert, update, upsert and index build; compound, sparse and partial unique indexes; TTL expiry (an expired document is gone from reads and deleted by the next write). Text and geo indexes are stored but not searchable. - Sessions:
lsidis accepted; a command carryingtxnNumberanswers the standalone server'sTransaction numbers are only allowed on a replica set member or mongos(20 IllegalOperation). - Planning: no index changes how a query runs; a
hintis validated (BadValue for a missing index) and$naturalorder is honoured, andexplainanswers no such command. - Not modeled: authentication (a connection string with credentials fails), TLS, compression, non-simple collations, capped collections, views, schema validation, change streams, and numeric subtypes (a stored double holding an integral value answers as int32).
Proofs: src/mongodb-driver.integration.test.ts (the driver), src/mongodb-mongoose.integration.test.ts
(mongoose models with a unique index and populate), src/mongodb-librechat.integration.test.ts
(LibreChat's schemas, indexes and message/conversation query shapes).
