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-crud-helper

v0.1.32

Published

A CRUD helper for Mongoose.

Downloads

28

Readme

mongoose-crud-helper

A simple helper library for Mongoose projects.

Installation

npm install mongoose-crud-helper

Configuration

Sample usage scenarios are explained below.

Changes to Model.js

You can directly code this to your model.

// Require the plugin in the top.
const MCHelper = require('mongoose-crud-helper');

// Add below after schema definition as required.
SchemaName.plugin(MCHelper.changeDocStatus);
SchemaName.plugin(MCHelper.getAllDocs);
SchemaName.plugin(MCHelper.getOneDoc);

Usage

You can directly code this to your controller.

1.changeDocStatus

const data = {
  _id:<Your-Object-ID>, // ObjectId
  status: '<New-Status>' // String (active, deleted, pending)
}; // Object

Model.changeDocStatus(data).then(function(response){
  // Your code here
});

2.getAllDocs

More info on customLabels referenced below is available at mongoose-paginate-v2

const where = {"$in": {status: ['active','pending']}}; // Object
const fieldsToDisplay = {postName: 1, description: 1, createdOn: 1 }; //Object
const myCustomLabels = {
	docs: 'data',
	nextPage: 'next',
	prevPage: 'prev',
	totalPages: 'pageCount'
};

const options = {
  select: fieldsToDisplay, // Object
  page: 1, // Number
  limit: 10, // Number
  lean: false, // Bool
  sortBy: 'createdOn', // String
  sortOrder: 'desc', // String
  populate: '', // String
  customLabels: myCustomLabels // Object
}; // Object

Model.getAllDocs(where, options).then(function(response){
  // Your code here
});

3.getOneDoc

const where = {"$in": {status: ['active','pending']}}; // Object
const fieldsToDisplay = {postName: 1, description: 1, createdOn: 1 }; //Object

Model.getOneDoc(where, fieldsToDisplay).then(function(response){
  // Your code here
});

4.hardDelete

const where = {"_id": ObjectId('57f79499cd3aa1000a5643b7')}; // Object

Model.hardDelete(where).then(function(response){
  // Your code here
});

5.softDelete

const where = {"_id": ObjectId('57f79499cd3aa1000a5643b7')}; // Object

Model.softDelete(where).then(function(response){
  // Your code here
});