New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-crud-helper

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-crud-helper

A CRUD helper for Mongoose.

  • 0.1.32
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

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
});

Keywords

FAQs

Package last updated on 17 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc