MongoDB (Mongoose) persistence adapter for SAP Cloud Application Programming Model
npm install cds-mongodbcds-mongodb enables CAP applications to use MongoDB as a native persistence layer, providing a developer experience consistent with official CAP database services such as @cap-js/sqlite and @cap-js/hana.
cds-mongodb bridges this gap without changing how developers write CDS models or services.
ObjectId references
$expand (Mongoose populate)
cds deploy --to mongoose support
db/data/*.csv
$expand for managed associations
$expand
bash
npm install cds-mongodb
`
---
Configuration
`json
{
"cds": {
"requires": {
"db": {
"kind": "mongoose",
"impl": "cds-mongodb",
"credentials": {
"url": "mongodb://localhost:27017/cap"
}
}
}
}
}
`
Or via environment variable:
`bash
export MONGO_URL=mongodb://localhost:27017/cap
`
---
Usage
$3
`cds
entity Authors {
key ID : UUID;
name : String;
books : Association to many Books;
}
entity Books {
key ID : UUID;
title : String;
author : Association to Authors;
}
`
$3
`cds
service CatalogService {
entity Authors as projection on Authors;
entity Books as projection on Books;
}
`
No custom handlers required.
---
Running Locally
`bash
cds deploy --to mongoose
cds run
`
---
CSV Seed Data
Place CSV files under:
`
db/data/
`
File name must match CDS entity name.
---
Association Handling
- Stored as MongoDB ObjectId references
- $expand translated to Mongoose populate
- Expand depth limited to 1
Example:
`
GET /catalog/Authors?$expand=books
`
---
Compatibility Matrix
| Component | Version |
|---------|---------|
| Node.js | >= 18 |
| @sap/cds | ^7.x |
| MongoDB | 6.x, 7.x |
| Mongoose | 8.x |
---
Logging & Errors
- Uses CAP logging (cds.log`)