I'm migrating a NodeJs project to NestJs, this project uses MongoDB as back-end database and Mongoose as ODM. I was using the [mongoose-sequence](https://github.com/ramiel/mongoose-sequence) plugin to handle autoincrement sequences, however I'm facing troubles requiring the library under NestJs.

The mongoose-sequence documentation explains how to import the library using CommonJS syntax as follows:

```
const mongoose = require('mongoose')
const AutoIncrementFactory = require('mongoose-sequence');

const connection = await mongoose.createConnection('mongodb://...');

const AutoIncrement = AutoIncrementFactory(connection);

```

Using ES6 import syntax it would be something like:

```
import * as mongoose from 'mongoose';
import * as AutoIncrementFactory from 'mongoose-sequence';

const connection = ...;

const AutoIncrement = AutoIncrementFactory(connection);

```

However since NestJs uses Dependency Injection, accessing the native connection is not so direct. According to the [documentation to integrate MongoDB using Mongoose](https://docs.nestjs.com/techniques/mongodb?source=post_page-----930a1d38a0a8----------------------#connection) accessing the native Mongoose Connection object can be done using the `@InjectConnection()` decorator as follows:

```
@Injectable()
export class CatsService {
  constructor(@InjectConnection() private connection: Connection) {}
}

```

But since [TypeScript decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) can only be attached to a class declaration, method, accessor, property, or parameter I don't see how to inject the connection, require the plugin and initialize it on my Schema classes.