Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
mongoose-strip-paths
Advanced tools
A mongoose plugin that deletes provided paths on a document and its sub documents, if any.
A mongoose plugin that deletes provided paths on a document and its sub documents, if any.
When instantiated, this plugin adds a static method stripPaths()
to your schema. Upon invoking this method, it loops over the provided paths in the options.paths
variable and sets them to undefined
. If there are any nested sub documents (via a single nested schema or embedded within an array), the stripPaths()
method of all respective sub documents is also invoked. This works for nested subdocuments as well as documents added via a populate query.
Note that there will be no validation done upon invoking the stripPaths()
method, which means that the document could be in an invalid state. As of version 0.0.2 stripPaths()
also returns a reference to the document for easy chaining.
This functionality should ideally only be used to return the document for further processing.
For example, given schemas as follows:
let mongoose = require("mongoose");
let mongooseStripPaths = require("mongoose-strip-paths").mongooseStripPaths;
let Schema = mongoose.Schema;
let PostSchema = new Schema({
title: String,
message: String,
fieldToStrip: String
});
PostSchema.plugin(mongooseStripPaths, { paths: ["fieldToStrip"] });
let UserSchema = new Schema({
username: String,
createdAt: { type: Date, required: true },
posts: [Post]
});
// note that if you add 'posts', then the posts field will be removed,
// also note that after stripping 'createdAt' mongoose validation will fail on trying to save it
UserSchema.plugin(mongooseStripPaths, { paths: ["createdAt"] });
let User = mongoose.model("User", UserSchema);
Calling the strip fields method on a user will result in the following document:
let user = new User({
username: 'u1',
createdAt: new Date(),
posts: []
});
user.posts.push({
title: 'first post',
message: 'hello',
fieldToStrip: 'some internal data'
});
user.posts.push({
title: 'second post',
message: 'world',
fieldToStrip: 'some more internal data'
});
user.stripPaths();
// user document is now
{
_id: ...,
username: 'u1',
posts: [
{
_id: ...,
title: 'first post',
message: 'hello'
},
{
_id: ...,
title: 'second post',
message: 'world'
}
]
}
// another example
let userObj = user.stripPaths().toObject();
path
: an array list of the required paths to remove. See object-path api for more path notations.>=6
>=2.6.10
>=4.11.0
npm install mongoose-strip-paths
npm install
and install mongo if you don't have it yet.mongod
.npm test
. Additionally you can pass your own mongodb uri as an environment variable if you would like to test against your own database, for e.g. URI='mongodb://username:password@localhost/mongoose-strip-paths-test' npm test
release-it patch,minor,major
npm version patch,minor,major
npm publish
_id
and __v
properties could be stripped on the root objectIssues, comments, PRs all welcome.
FAQs
A mongoose plugin that deletes provided paths on a document and its sub documents, if any.
The npm package mongoose-strip-paths receives a total of 2 weekly downloads. As such, mongoose-strip-paths popularity was classified as not popular.
We found that mongoose-strip-paths demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.