Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
bridge-mongo
Advanced tools
A mongodb ORM on top of mongoose that match perfectly with the Bridge framework
Bridge-mongo is a typed framework built on top of Mongoose, the popular MongoDB object-document mapping (ODM) library. It provides a type-safe approach to querying MongoDB databases that makes it almost impossible to write poorly constructed queries, all while using the same syntax as Mongoose.
👉 See more informations on mongo.bridge.codes 👈
Full documentation for bridge-mongo
can be found here.
# npm
npm install bridge-mongo
# Yarn
yarn add bridge-mongo
# pnpm
pnpm add bridge-mongo
Defining your schemas in bridge-mongo is just as easy as it is with Mongoose. You can define your schemas using Mongoose's schema syntax, and then use the createDB function to create your models.
When you use createDB
, bridge-mongo will automatically create and register each model with Mongoose using the keys from your schema object as the model names. This means you can define all of your schemas in one place and have them automatically created and registered as models for you.
import { createDB, Schema, mongoose } from 'bridge-mongo';
// Defining a User Schema
const userSchema = new Schema({
name: { type: String, required: true },
email: String,
age: { type: Number, default: 18 },
job: { type: String, enum: ['developer', 'designer'] },
settings: {
isActive: Boolean,
},
});
// Defining a Post Schema
const postSchema = new Schema(
{
text: { type: String, required: true },
userId: { type: mongoose.Types.ObjectId, req: true },
likes: Number,
},
{ timestamps: true },
);
// The keys correspond to the model Name
const DB = createDB({
User: userSchema,
Post: postSchema,
});
Connecting to your MongoDB database using bridge-mongo is just as easy as it is with Mongoose. In fact, you can import mongoose
directly from bridge-mongo and use its connect function to connect to your database.
import { mongoose } from 'bridge-mongo';
const launch = async () => {
await mongoose.connect('Your MongoDB URL here');
console.log('Connected!')
}
launch();
You can enjoy the benefits of total type safety and guidance through TypeScript. The fully typed query results and error handling provided by bridge-mongo make it easy to write correct, efficient queries with confidence.
Read the documentation to get started or get a look to the examples below.
Some Queries examples:
import { isError } from 'bridge-mongo';
async () => {
const user = await DB.user.create({ name: 'Nab' });
const post = await DB.post.findOne({ userId: user._id }, {text: 1});
if (!isError(post)) console.log(post)
const posts = await DB.post.find({ likes: { $gt: 10 }});
const res = await DB.user.findByIdAndUpdate(user._id, { name: 'Neo' }, { projection: { name: 1 } })
}
Some Aggregate examples:
async () => {
// Fetching all users that have created post with their posts
const blogers = await DB.user
.aggregate()
.project({ name: 1 })
.lookup({ from: 'posts', localField: '_id', foreignField: 'userId' })
.match({ 'posts.0': { $exists: true } })
.exec();
// Fetching all posts from the last 24 hours with their author only if he's >= 21 years old
const yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
const posts = await DB.post
.aggregate()
.project({ text: 1, createdAt: 1, userId: 1 })
.match({ createdAt: { $gt: yesterday } })
.lookup({ from: 'users', let: { userId: '$userId' }, as: 'user' }, (user, { userId }) =>
user
.match({ $expr: { $eq: ['$_id', userId] }, age: { $gte: 21 } })
.project({ name: 1 })
.limit(1),
)
.unwind('$user')
.unset('userId')
.exec();
}
Bridge-mongo is constantly evolving and adding new features to provide a fully typed, robust, and easy-to-use interface for interacting with MongoDB. While many essential functions are already implemented, there are still many more features that can be added to meet specific use cases. If you are interested in contributing or discussing features that you'd like to see implemented, you can join the Bridge-mongo Discord server and be a part of the community.
FAQs
A mongodb ORM on top of mongoose that match perfectly with the Bridge framework
The npm package bridge-mongo receives a total of 38 weekly downloads. As such, bridge-mongo popularity was classified as not popular.
We found that bridge-mongo 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.