Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-monorepo-parallel/llms.txt
Use this file to discover all available pages before exploring further.
BaseCRUD is exported from packages/core/src/lib/common/BaseCRUD.ts and serves as the base class for all database services in @pro/core. It uses di-factory’s factory() helper to produce a mixin class that accepts any Mongoose Model and exposes a standard set of CRUD operations, all instrumented with LoggerService and normalised through readTransform.
Constructor
BaseCRUD by calling it as a function with your Mongoose model:
Any Mongoose model. The model’s
modelName is used in log messages to identify which collection is being operated on.Methods
create()
loggerService.info, then calls TargetModel.create(dto) and returns the plain-object representation via readTransform.
The document payload. Must conform to the model’s schema.
id (not _id) and no internal Mongoose fields.
update()
_id using findByIdAndUpdate with { new: true, runValidators: true }. The id field is stripped from dto before the update to prevent accidental overwrites.
The MongoDB
_id of the document to update.Partial update payload. The
id key is omitted automatically via lodash.omit.Error: <ModelName> not found if no document matches the given id.
findById()
_id.
The MongoDB
_id string to look up.Error: <ModelName> not found if the document does not exist.
findByFilter()
filterData. Wraps Mongoose findOne.
A Mongoose query filter (e.g.
{ symbol: "BTCUSDT", interval: "1h" }).Optional sort spec (e.g.
{ date: -1 }). Passed directly to Mongoose.null if nothing matches.
findAll()
FIND_ALL_LIMIT (1 000) documents sorted by date descending.
Optional Mongoose query filter. Defaults to
{} (all documents).Maximum number of documents to return. Defaults to
1000.iterate()
find. Memory-efficient for large collections because it does not load the full result set into memory.
Optional Mongoose query filter. Defaults to
{}.Optional sort spec.
paginate()
Mongoose query filter applied to both the page query and the
countDocuments call.Optional sort spec.
The current page of plain-object documents.
Total number of documents matching
filterData, regardless of pagination.Concrete Example: CandleDbService
CandleDbService extends BaseCRUD(CandleModel) and overrides create() to perform an atomic upsert — preventing duplicate candles for the same symbol/interval/timestamp combination:
$setOnInsert operator means the document fields are only written on a true insert — if a matching candle already exists, the operation is a no-op.
readTransform converts Mongoose documents to plain objects: it renames _id to id and strips internal Mongoose metadata fields such as __v. All methods in BaseCRUD run their return values through this transform automatically.