Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@saddamhmalik/mongodb-query-builder
Advanced tools
A MongoDB query builder for Node.js applications, inspired by Laravel's query builder.
The MongoDB Query Builder is a Node.js library inspired by Laravel's query builder, designed to simplify the process of constructing MongoDB queries in Node.js applications.
To install the MongoDB Query Builder library, simply run:
npm install mongodb-query-builder
const { MongoClient } = require('mongodb');
const QueryBuilder = require('mongodb-query-builder');
// Connect to MongoDB
const client = new MongoClient('mongodb://localhost:27017', { useNewUrlParser: true, useUnifiedTopology: true });
await client.connect();
try {
// Get reference to the database
const db = client.db('your_database_name');
// Create a QueryBuilder instance with a collection
const collection = db.collection('your_collection_name');
const qb = new QueryBuilder(collection);
// Perform queries using QueryBuilder methods
// 1. Where Clause
const results1 = await qb.where('field', '=', 'value').get();
console.log('Where Clause results:', results1);
// 2. OrWhere Clause
const results2 = await qb.where('age', '>', 30).orWhere('city', '=', 'New York').get();
console.log('OrWhere Clause results:', results2);
// 3. Select
const results3 = await qb.select(['name', 'age']).get();
console.log('Select results:', results3);
// 4. Order By
const results4 = await qb.orderBy('age', 'desc').get();
console.log('Order By results:', results4);
// 5. Limit and Skip
const results5 = await qb.limit(10).skip(5).get();
console.log('Limit and Skip results:', results5);
// 6. Join
const ordersCollection = db.collection('orders');
const results6 = await qb.join('orders', '_id', 'user_id', 'orders').get();
console.log('Join results:', results6);
} finally {
// Close the connection
await client.close();
}
The where method is used to filter documents based on specific criteria.
// Where Clause Usage
const results = await qb.where('field', '=', 'value').get();
console.log('Where Clause results:', results);
The orWhere method allows you to add additional conditions with logical OR operations.
// OrWhere Clause Usage
const results = await qb.where('age', '>', 30).orWhere('city', '=', 'New York').get();
console.log('OrWhere Clause results:', results);
The select method is used to specify which fields to include in the query results.
// Select Usage
const results = await qb.select(['name', 'age']).get();
console.log('Select results:', results);
The orderBy method is used to sort the query results based on a field and direction.
The limit and skip methods are used to limit the number of results returned and skip a specified number of documents.
// Limit and Skip Usage
const results = await qb.limit(10).skip(5).get();
console.log('Limit and Skip results:', results);
The join method is used to perform inner join operations between collections.
// Join Usage
const ordersCollection = db.collection('orders');
const results = await qb.join('orders', '_id', 'user_id', 'orders').get();
console.log('Join results:', results);
Provides an intuitive and fluent interface for building MongoDB queries. Supports common query operations such as where, orWhere, select, orderBy, limit, and skip. Enables advanced query capabilities like join operations between collections. Lightweight and easy to integrate into existing Node.js projects.
Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the ISC License.
FAQs
A MongoDB query builder for Node.js applications, inspired by Laravel's query builder.
The npm package @saddamhmalik/mongodb-query-builder receives a total of 1 weekly downloads. As such, @saddamhmalik/mongodb-query-builder popularity was classified as not popular.
We found that @saddamhmalik/mongodb-query-builder demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.