Recipes
Directory navigation
- Only connect to MongoDB
- Enable memory cache
- Enable Redis second-level cache and distributed invalidation
- Connect to intranet MongoDB through SSH tunnel
- Configuring multiple connection pools
- Use business lock
- Enable Model layer
- Troubleshooting by error code
Only connect to MongoDB
It is suitable to verify the connection, CRUD and package entry first. Missing config.uri throws INVALID_CONFIG, and directly accessing the data without connect() throws NOT_CONNECTED.
Enable memory cache
Memory caching requires no additional services and is suitable for single-process or local fast verification.
Enable Redis second-level cache and distributed invalidation
ioredis has been installed by default with monsqlize; what needs to be configured here is the Redis address and whether to enable distributed failure, rather than installing dependencies.
Connect to intranet MongoDB through SSH tunnel
ssh2 is installed by default with monsqlize. As long as config.ssh is passed in, the runtime will establish a local tunnel and forward the MongoDB connection to the intranet address.
Configure multiple connection pools
A connection pool configuration error will throw INVALID_CONFIG; specifying a non-existent pool will throw POOL_NOT_FOUND; unavailability of all pools will throw INVALID_OPERATION.
Use business lock
Single-process scenarios use memory locks by default; cross-instance scenarios can pass in Redis related configurations to enable distributed lock capabilities.
Enable Model layer
schema-dsl is installed by default with monsqlize. Only when the application code directly imports schema-dsl, it needs to be declared in the application's own dependencies.
Troubleshoot according to error code
For more error codes and handling suggestions, see error-codes.md.