npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-search

v4.2.2

Published

a simple pagination library made for nestjs(mongoose and aws documentdb) by zero2hero

Downloads

28

Readme

NestJS Search

Search package for NestJS with MongoDb and AWS DocumentDB

PS, It is a copy of Nestjs-Keyset-Paginator, was added new features(i.e. between was added)

Installation

Use the package manager npm to install NestJS Search.

npm i nestjs-search

Usage

  • In example.controller.ts use PaginationDto to Validate params and pass it to service.
import { PaginationDto, projectionDto } from 'nestjs-search'

@Controller('example')
export class ExampleController {
    constructor(private readonly exampleService: ExampleService) {}

    @Get()
    findAll(@Body() params: PaginationDto) {
        return this.exampleService.findAll(
            params.skip,
            params.limit,
            params?.start_key,
            params?.sort?.field,
            params?.sort?.order,
            params?.filter,
            params?.projection
        )
    }
}
  • Then in example.service.ts pass those params to "paginate()" along with you model (Mongoose Model).
import paginate, { filterDto, projectionDto } from 'nestjs-search'

@Injectable()
export class ExampleService {
    constructor(
        @Inject(EXAMPLE_MODEL)
        private readonly exampleModel: Model<ExampleDocument>
    ) {}

    async findAll(
        skip = 0,
        limit = 10,
        start_key?,
        sort_field?: string,
        sort_order?: number,
        filter?: filterDto[],
        projection?: projectionDto[]
    ) {
        return paginate(this.exampleModel, skip, limit, start_key, sort_field, sort_order, filter, projection)
    }
}
  • Paginate function will return with promise of:
{ docs: docs, next_key }

Example param

Example:-

{
    "filter": [
        {
            "name": "score",
            "value": 400,
            "operator": "lt"
        },
        {
            "name": "isPassed",
            "value": true,
            "operator": "eq"
        },
        {
            "name": ["outer_field_name", "inner_field_name"],
            "value": "user one",
            "operator": "eq"
        },
        {
            "name": "time",
            "arr_value": [40, 60],
            "operator": "in"
        },
        {
            "name": "left_count",
            "arr_value": [0, 1],
            "operator": "nin"
        }
    ],
    "sort": {
        "field": "score",
        "order": 1
    },
    "projection": [
        {
            "name": "password",
            "mode": 0
        }
    ],
    "limit": 4
}

Please note: for the same same field, when you use "lt" and "gt" filters at the same time, the filters overriding each other, instead please use "between" as follows.

Example: between

{
    "filter": [
        {
            "name": "eventStartDateTime",
            "arr_value": ["2021-11-16", "2021-11-17"],
            "operator": "between"
        }
    ]
}

or any other ISODate

{
    "filter": [
        {
            "name": "eventStartDateTime",
            "arr_value": ["2021-11-16T11:30:01.001+00:00", "2021-11-17T11:30:01.001+00:00"],
            "operator": "between"
        }
    ]
}

Example: fulltext search Please note: Aws DocumentDB doesn't support fulltext search now(suggests Elastic Search instead). Therefore, you cannot use this search on DocDB. Instead, you can use like search option like we shown on the next example.

{
    "filter": [
        {
            "name": "text",
            "value": "zero2hero metaverse event",
            "operator": "search"
        }
    ]
}

it works regarding to MongoDb Text Indexes, the document link: https://www.mongodb.com/docs/manual/core/index-text/

Example: Like search on multiple fields Please note: Aws DocumentDB doesn't support fulltext search now(suggests Elastic Search instead). Therefore, we added enhanced like search on multiple field. Just keep in your mind, more data will consume more CPU and memory on here. You may think to move to MongoDB to save some cost instead.

{
    "filter": [
        {
            "name": "groupName",
            "value": "Test",
            "operator": "like",
            "mode": "bnm"
        },
        {
            "name": "groupDetails.groupDetails",
            "value": "test",
            "operator": "like",
            "mode": "bnm"
        }
    ]
}

it works regarding to MongoDb Text Indexes, the document link: https://www.mongodb.com/docs/manual/core/index-text/

Example: in

{
    "filter": [
        {
            "name": "eventCategory",
            "arr_value": ["sport", "training"],
            "operator": "in"
        }
    ]
}
  • As response, you will also get "next_key".

Example:

{
    "next_key": [
        {
            "key": "_id",
            "value": "61a4c444f9534392c70afaf6"
        },
        {
            "key": "score",
            "value": 100
        }
    ]
}
  • To get next page use this "next_key" object as "start_key" in next request.

Example:

{
    "filter": [
        {
            "name": "score",
            "value": 400,
            "operator": "lt"
        },
        {
            "name": "isPassed",
            "value": true,
            "operator": "eq"
        }
    ],
    "sort": {
        "field": "score",
        "order": 1
    },
    "limit": 4,
    "start_key": [
        {
            "key": "_id",
            "value": "61a4c444f9534392c70afaf6"
        },
        {
            "key": "score",
            "value": 100
        }
    ]
}
  • If you provide "start_key" this will skip previous Documents.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate if applicable.

License

MIT