Skip to content

MemoryCrate

Stores items in a Json[] array. No persistence — data is lost when the process exits. Useful for testing, prototyping, and development.

import crate.collection.memory;
auto products = new MemoryCrate!Product;
router.crateSetup!RestApi.add(products);

With config:

auto config = CrateConfig!Product();
config.deleteItem = false;
auto products = new MemoryCrate!Product(config);
  • Storage: Json[] array in memory
  • ID generation: Auto-generates BsonObjectID strings on insert
  • Queries: Uses BsonQueryBuilder internally, so query syntax is identical to MongoCrate
  • Filtering: itemFilter() evaluates Bson query patterns against in-memory items
  • No persistence: Data exists only for the lifetime of the process

MemoryCrate supports the full IQuery interface — where, sort, limit, skip, distinct, searchText, and field projections. The BsonQueryBuilder ensures the same query syntax works whether you’re using Memory or Mongo as the backend, making it easy to swap between them.

  • Unit and integration tests
  • Rapid prototyping
  • Development without a database
  • Small datasets that fit in memory