
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
express-mongoose-loader
Advanced tools
Create mongodb models loaders scripts for your express app
Create MongoDB models loaders scripts for your express app, saving you thoses numerous database requests.
$ npm install express-mongoose-loader
First call for express-mongoose-loader
to set up loading system.
app.use(require('express-mongoose-loader'));
Then, create a mongoose model loader by requesting mongoose id list to load
with the function req.requestList(listName)
. Add item's data into the object
req.db[listName]
created by express-mongoose-loader
.
import mongoose from 'mongoose';
import Article from './model/article';
let articlesLoaders = (req, res , next) => {
Article.find(
{
_id: { $in: req.requestList('articles') }
},
(err, docs) => {
if (!err && docs) {
for (const doc of docs) {
req.db.articles[doc.id] = {
title: doc.title,
datetime: doc.datetime,
content: doc.content
};
}
}
next();
}
);
}
Request model's item loading by calling the function req.load(id)
.
req.load('57f0c59a779f68ea0a70a4e2');
After requesting a load you must call your model loader middleware.
app.use(articlesLoaders);
/* Init your express app */
import express from 'express';
import mongooseLoader from 'express-mongoose-loader';
import mongoose from 'mongoose';
mongoose.connect(/* DB config */);
const app = express();
app.listen(8080);
app.use(mongooseLoader);
/* Create a basic mongoose model */
var ArticleSchema = new mongoose.Schema({
title: String,
datetime: Date,
content: String
});
const Article = mongoose.model('article', ArticleSchema);
/* Create a basic mongoose loader */
let articlesLoaders = (req, res, next) => {
Article.find(
{
_id: { $in: req.requestList('articles') }
},
(err, docs) => {
if (!err && docs) {
for (const doc of docs) {
req.db.articles[doc.id] = {
title: doc.title,
datetime: doc.datetime,
content: doc.content
};
}
}
next();
}
);
}
/* Create a basic articles loader middleware */
let loadArticles = (req, res, next) => {
Article.find(
{
public: true
},
(err, articles) => {
if (!err && articles) {
for (const article of articles) {
/* Ask for article data loading */
req.load('articles', article.id);
}
}
}
);
}
/* Basic index page */
app.use([loadArticles, articlesLoaders]);
app.get('/',
(req, res) => {
let content = '';
for (const article of req.db.articles) {
content += '<h1>' + article.title + '</h1><br />';
}
res.send(content);
}
);
This project is licensed under the MIT license.
FAQs
Create mongodb models loaders scripts for your express app
The npm package express-mongoose-loader receives a total of 2 weekly downloads. As such, express-mongoose-loader popularity was classified as not popular.
We found that express-mongoose-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.