npm.io
1.0.1 • Published 2 years ago

mongoose-anonymoose

Licence
MIT
Version
1.0.1
Deps
1
Size
4 kB
Vulns
0
Weekly
0

Mongoose Anonymoose

Description

This plugin removes _id and __v fields from the objects when you call the methods toJson and toObject.

Installation

yarn
yarn add mongoose-anonymoose
npm
npm i mongoose-anonymoose
pnpm
pnpm i mongoose-anonymoose
bun.js
bun install mongoose-anonymoose

Usage

Connection scope

connection = await mongoose.connect(options)
connection.plugin(anonymoose);

Query level scope

export class UsersRepository {
    public async findOne(uuid: string): Promise<User> {
        const user = await UserModel.findOne({ uuid });
        if (user) {
            return User.instance(user.toJson());
        }
    
        return null;
    }
}