Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ucast/mongo2js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ucast/mongo2js

git@github.com:stalniy/ucast.git

  • 1.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
526K
decreased by-8.56%
Maintainers
1
Weekly downloads
 
Created

What is @ucast/mongo2js?

@ucast/mongo2js is a utility library that converts MongoDB query objects into JavaScript functions. This can be particularly useful for filtering data in JavaScript applications using the same query syntax as MongoDB.

What are @ucast/mongo2js's main functionalities?

Convert MongoDB Query to JavaScript Function

This feature allows you to convert a MongoDB query object into a JavaScript function that can be used to filter arrays of objects. In this example, the query filters out objects where the age is greater than 18.

const { compile } = require('@ucast/mongo2js');

const query = { age: { $gt: 18 } };
const filterFunction = compile(query);

const data = [
  { name: 'Alice', age: 17 },
  { name: 'Bob', age: 20 },
  { name: 'Charlie', age: 22 }
];

const filteredData = data.filter(filterFunction);
console.log(filteredData); // Output: [{ name: 'Bob', age: 20 }, { name: 'Charlie', age: 22 }]

Support for Complex Queries

This feature supports complex MongoDB queries, including logical operators like $and. In this example, the query filters out objects where the age is greater than 18 and the name contains the letter 'B'.

const { compile } = require('@ucast/mongo2js');

const query = { $and: [ { age: { $gt: 18 } }, { name: { $regex: 'B' } } ] };
const filterFunction = compile(query);

const data = [
  { name: 'Alice', age: 17 },
  { name: 'Bob', age: 20 },
  { name: 'Charlie', age: 22 }
];

const filteredData = data.filter(filterFunction);
console.log(filteredData); // Output: [{ name: 'Bob', age: 20 }]

Other packages similar to @ucast/mongo2js

Keywords

FAQs

Package last updated on 15 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc