
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
mongoose-null-error
Advanced tools
A Mongoose plugin for enforcing validation against null values returned by certain query operations.
mongoose-null-error
is a plugin for Mongoose that provides functionality to enforce validation against null values returned by certain query operations. It'll throw an error if query return value is null.
You can install mongoose-null-error
via npm:
npm install mongoose-null-error
yarn add mongoose-null-error
To use mongoose-null-error
, apply the plugin to your Mongoose schema definition and pass the desired options when performing query operations.
import mongoose from 'mongoose'
import mongooseNullError from 'mongoose-null-error'
// Define your Mongoose schema
const MySchema = new mongoose.Schema({
// Define your schema fields
})
// Apply the mongoose-null-error plugin to your schema
MySchema.plugin(mongooseNullError)
// Define your Mongoose model
const MyModel = mongoose.model('MyModel', MySchema)
When performing query operations such as findOne
, findById
, findByIdAndUpdate
,findOneAndUpdate
, findByIdAndDelete
, findOneAndDelete
, or findOneAndReplace
, you can pass an option to enable null error validation.
// Example usage with findById
try {
const user = await User.findById(id, '', { mongooseNullError: true })
// Handle successful query
} catch (error) {
// Handle error thrown due to null value
console.error(error.message)
}
When the specified query operation returns a null value and the mongooseNullError
option is set to true
, an error will be thrown to indicate an invalid request.
We welcome contributions from the community. If you want to contribute to this project.
This project is licensed under the MIT License.
For questions, feedback, or support, please feel free to contact at personal.sifat@gmail.com.
FAQs
A Mongoose plugin for enforcing validation against null values returned by certain query operations.
We found that mongoose-null-error 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.