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

mongoose-querier

v1.2.0

Published

Easy to use Mongoose plugin which helps in querying Schema and supports pagination, filters, selection, searching, sorting.

Downloads

4

Readme

mongoose-querier

npm version Dependency Status Dev Dependency Status contributions welcome Downloads Github

Mongoose plugin which helps in querying Schema and supports pagination, filters, selection, searching, sorting.

NPM

Table of Contents

  1. Installation
  2. Setup
  3. Usage
  4. API
  5. License

Installation

npm install mongoose-querier -S

Setup

Add mongoose-paginate-v2 plugin and index the schema.

const mongoose         = require('mongoose');
const mongoosePaginate = require('mongoose-paginate-v2');

const bookSchema = new Schema({
    author: { type: Schema.Types.ObjectId, ref: 'Author' },
    title: String,
    genre: String,
    publishDate: Date
});

bookSchema.plugin(mongoosePaginate);

bookSchema.index({ '$**': 'text' });

module.exports = mongoose.model('Book',  bookSchema);

Usage

// import plugin
const Querier = require('mongoose-querier');

// import Book Schema
const Book = require('./Book');

const method = async () => {
    const data = {
        id: 'list',
        options: {
            select: ['_id', 'title'],
        },
    };
    const populate = [{ path: 'author', model: 'Author' }];
    const res = await Querier(Book, data, populate);
};

API

await Querier([schema], [data], [populate], [defaultQuery]);

Parameters

  • [schema] {Object} Mongoose Schema Model (required)
  • [data] {Object} (required)
    • id {String} Can be valid Mongoose ObjectId or list (required)
    • filters {Object[]} Data for performing filters (optional)
      • type {String} Can be match or multi or date
      • key {String} Schema field on which the filter operation will be performed
      • data {Any} Data to perform the filter
    • options {Object} Options for plugin (optional)
      • select {String[]} Keys which has to be present in the response (optional, by default sends all key)
      • search {String} Schema wide search (optional, by default value is null)
  • populate {Object[]} Mongoose Populate wihch takes in array of objects (optional)
  • defaultQuery {Object} Default queries can also be passed here (optional, by default it's empty)

Examples of data.filters field

[
    { type: 'match', key: 'author', data: 'ObjectId' },
    { type: 'multi', key: 'genre', data: ['Fantasy', 'Horror'] },
    { type: 'date', key: 'publishDate', data: { from: 'date', to: 'date' } },
]

License

MIT