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

mongoose-hidden

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-hidden

Hides certain model properties when invoking toJSON or toObject.

0.1.1
Source
npm
Version published
Weekly downloads
4.6K
-6.45%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-hidden

build status

A Mongoose schema plugin that hooks into toJSON and toObject to allow filtering of properties you usually do not want to sent client-side.

Intall

npm install mongoose-hidden

Usage

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    mongooseHidden = require('mongoose-hidden');

var UserSchema = new Schema(
    name: String,
    password: { type: String, hide: true },
    email: String
);

UserSchema.plugin(mongooseHidden);

var User = mongoose.model('User', UserSchema);
var user = new User({ name: "Joe", email: "joe@example.com", password: "secret" });
user.save(function() {
    var jsonUser = user.toJSON();
    console.log(jsonUser);

    // Outputs: { name: "Joe", email: "joe@example.com" }
});

In stead of hide: true you can specify the property to only be hiden for toJSON or toObject be writing: hideJSON: true or hideObject respectivly.

TODO

  • Implement turning on and off on a single invocation (if possible). Something like this:

    var jsonUser = user.toJSON({ hide: false });

Keywords

mongoose

FAQs

Package last updated on 01 Jul 2014

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