MongoCrate
Stores items in a MongoDB collection. Production-ready with full query support, geospatial queries, text search, and ObjectId handling.
import crate.collection.mongo;
// From a collection objectauto products = new MongoCrate!Product(mongoCollection);
// From a client + collection nameauto products = new MongoCrate!Product(mongoClient, "products");
router.crateSetup!RestApi.add(products);With config:
auto config = CrateConfig!Product();config.deleteItem = false;
auto products = new MongoCrate!Product(mongoCollection, config);How It Works
Section titled “How It Works”- Storage: MongoDB collection via vibe.d’s MongoDB driver
- ID generation: Auto-generates
BsonObjectIDon insert - Queries: Native MongoDB queries via
BsonQueryBuilder - Streaming: Results are streamed via
InputRange!Json— large collections don’t load entirely into memory - ObjectId handling: Automatically converts string IDs to
BsonObjectIDfor queries
Query Support
Section titled “Query Support”Full MongoDB query capabilities through the IQuery interface:
crate.get() .where("status").equal("active").and() .where("tags").arrayContains("featured").and() .where("position").near(longitude, latitude, 5000).and() // Geospatial .sort("createdAt", -1) .limit(50) .skip(100) .exec();Supported query operators include equal, like, anyOf, greaterThan, lessThan, arrayContains, containsAll, insidePolygon, intersects, near, not, and or.
SysTime Handling
Section titled “SysTime Handling”ISO date strings in query values are automatically converted to BsonDate for proper MongoDB date comparisons.
Nested Struct Support
Section titled “Nested Struct Support”MongoCrate recursively processes nested structs, converting model references to their ID representation for storage and resolving them back on retrieval.