Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
DatabaseModule
✓ import { DatabaseModule } from 'zync-nest-data-module';
✗ const { DatabaseModule } = require('zync-nest-data-module');
Primary module for MongoDB/Mongoose integration. Used in NestJS `imports` array.
BackupModule
✓ import { BackupModule } from 'zync-nest-data-module';
✗ const BackupModule = require('zync-nest-data-module').BackupModule;
Module for automated database backup services. Also used in NestJS `imports`.
BaseService
✓ import { BaseService } from 'zync-nest-data-module';
Generic base class for creating application services with common CRUD and pagination methods.
BaseSchema
✓ import { BaseSchema } from 'zync-nest-data-module';
A Mongoose schema class providing common fields like `_id`, `createdAt`, `updatedAt`, and `isDeleted` for soft deletion.
AbstractBaseRepository
✓ import { AbstractBaseRepository, IPageParams } from 'zync-nest-data-module';
Abstract class for implementing repositories with standard database operations. `IPageParams` is an interface for pagination.
TransactionManager
✓ import { TransactionManager } from 'zync-nest-data-module';
Service for managing Mongoose transactions, ensuring atomicity for complex operations.
Demonstrates the basic setup of the Zync NestJS Data Module in an AppModule, including how to define a Mongoose schema extending `BaseSchema` and how to implement a custom repository using `AbstractBaseRepository`, showcasing common database patterns.
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Injectable } from '@nestjs/common';
import { SoftDeleteModel } from 'mongoose-delete';
import {
DatabaseModule,
BackupModule,
BaseSchema,
AbstractBaseRepository,
IPageParams
} from 'zync-nest-data-module';
// 1. Define your Mongoose Schema extending BaseSchema
@Schema({
timestamps: true,
collection: 'my_documents'
})
export class MyDocument extends BaseSchema {
@Prop({ required: true, unique: true })
name: string;
@Prop()
description?: string;
}
export const MyDocumentSchema = SchemaFactory.createForClass(MyDocument);
// 2. Create your custom repository
@Injectable()
export class MyRepository extends AbstractBaseRepository<MyDocument> {
constructor(@MongooseInjectModel(MyDocument.name) model: SoftDeleteModel<MyDocument>) {
super(model);
}
protected buildQuery(query: Partial<MyDocument>): any {
return query;
}
public async mapData(data: any, isCreate: boolean): Promise<MyDocument> {
return data;
}
async findByName(name: string): Promise<MyDocument[]> {
return this.find({ name });
}
}
// 3. Set up your NestJS AppModule
@Module({
imports: [
MongooseModule.forRoot(process.env.MONGODB_URI ?? 'mongodb://localhost/test'),
MongooseModule.forFeature([{ name: MyDocument.name, schema: MyDocumentSchema }]),
DatabaseModule, // Integrates core database utilities
BackupModule, // Integrates database backup service
],
providers: [MyRepository],
exports: [MyRepository]
})
export class AppModule {}
// Note: MongooseInjectModel is a placeholder. In a real app, use @nestjs/mongoose's @InjectModel.
// The code above uses a common alias 'MongooseInjectModel' to avoid direct import conflict for example clarity.
Errors
Common errors & fixes
Error: Cannot find module 'zync-nest-data-module'
The package was attempted to be installed from the public npm registry instead of the private AsyncTech registry.
fixInstall using `npm install zync-nest-data-module --registry https://registry.asynctechs.com/` or `pnpm add zync-nest-data-module --registry https://registry.asynctechs.com/`.
Nest can't resolve dependencies of the [Service/Repository]. Please make sure that the argument at index [X] is available in the [Module] context.
A required provider (e.g., a custom repository, `TransactionManager`) or module (e.g., `DatabaseModule`, `MongooseModule`) was not correctly imported or provided in the respective NestJS module.
fixEnsure that `DatabaseModule` and `BackupModule` are included in the `imports` array of your application's module. If using custom repositories, ensure they are listed in the `providers` array of the consuming module, and that `MongooseModule.forFeature()` is correctly configured for their schemas.
MongooseError: The 'uri' parameter to 'openUri()' must be a string, got "undefined"
The MongoDB connection URI provided to `MongooseModule.forRoot()` is undefined or null, likely due to a missing environment variable.
fixSet the `MONGODB_URI` environment variable (e.g., `mongodb://localhost:27017/mydatabase`) or ensure your NestJS configuration correctly passes the database URI to `MongooseModule.forRoot()`.
MongooseError: Transaction numbers are only allowed on replica sets. Please make sure that your MongoDB instance is running as a replica set.
Attempting to use Mongoose transactions (via `TransactionManager`) with a standalone MongoDB instance, which does not support transactions.
fixConfigure your MongoDB server as a replica set. For local development, you can start a single-node replica set. Refer to MongoDB documentation for replica set setup.
Audit
Dependencies
@nestjs/mongooserequiredCore integration with Mongoose within the NestJS framework for database operations.
@nestjs/schedulerequiredUsed for scheduling automated tasks, likely for the database backup service.
@types/nanoidrequiredTypeScript type definitions for the `nanoid` package.
mongooserequiredThe primary Object Data Modeling (ODM) library for MongoDB.
nanoidrequiredGenerates compact, URL-friendly, unique IDs.
nest-winstonoptionalIntegrates Winston logger into NestJS applications for robust logging capabilities.
randomaticrequiredUtility for generating random strings, likely used for unique identifiers or tokens.
redis-omoptionalRedis Object Mapper for simplified interaction with Redis. Its usage is not detailed in the README excerpt but is listed as a peer dependency.