npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@swimlane/rql-to-mongo

v1.0.0

Published

Converts an RQL object to a mongo query object

Downloads

5,361

Readme

rql-to-mongo

Convert RQL into MongoDB queries

Build
Status

Example

import { MongoQuery, RQLToMongo } from '@swimlane/rql-to-mongo';
import { RQLQuery } from '@swimlane/rql';

const rqlQuery: RQLQuery = RQLQuery.parse('eq(foo,3)&sort(-date)&limit(100,10)');
const mongoQuery = RQLToMongo.convertRQLQuery(rqlQuery);

cursor = db.collection.find(mongoQuery.criteria, {
	skip: mongoQuery.skip,
	limit: mongoQuery.limit,
	sort: mongoQuery.sort
});

cursor.toArray(function (err, docs) {
	// ...
});

Supported RQL operators

Only a limited set of operators are currently supported:

Comparison

  • eq(field,value): Mongo operator $eq. Matches values that are equal to a specified value.
  • gt(field,value): Mongo operator $gt. Matches values that are greater than a specified value.
  • ge(field,value): Mongo operator $gte. Matches values that are greater than or equal to a specified value.
  • in(field,arrayValue): Mongo operator $in. Matches any of the values specified in an array.
  • lt(field,value): Mongo operator $lt. Matches values that are less than a specified value.
  • le(field,value): Mongo operator $lte. Matches values that are less than or equal to a specified value.
  • ne(field,value): Mongo operator $ne. Matches all values that are not equal to a specified value.
  • out(field,value): Mongo operator $nin. Matches none of the values specified in an array.

Logical operators

  • and(rqlQuery1,rqlQuery2...): Mongo operator $and. Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
  • or(rqlQuery1,rqlQuery2...): Mongo operator $or. Joins query clauses with a logical OR returns all documents that match the conditions of either clause.

Paging operators

  • sort(+field1,-field2): Sorts the results. + for ascending, - for descending.
  • limit(maximum,skip): Takes two args: maximum is a number which indicates the maximum number of results to return. Skip is a number which indicates how many items should be skipped before collecting the results
  • after(cursor): Takes a cursor identifying where to start the page of results
  • before(cursor): Takes a cursor identifying where to start a page of results going backwards in the list

Note: Cursor paginating using before() and after() is not directly supported by MongoDB. It requires some extra code or another library such as mongo-cursor-pagination to use these.

MongoQuery

The result object which is used for querying MongoDB:

  • after: string; The cursor identifying which item to skip to when collecting a result set
  • before: string; The cursor identifying the last item when collecting a result set going backwards
  • skip: number; The number of items to skip before collecting the results
  • limit: number; The maximum number of results to return
  • criteria: any; The MongoDB query criteria
  • sort: object; The MongoDB sorting criteria

Install

With npm do:

npm install @swimlane/rql-to-mongo

Credits

rql-to-mongo is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.

SecOps Hub is an open, product-agnostic, online community for security professionals to share ideas, use cases, best practices, and incident response strategies.