Skip to content

MongoDB and Redis queries are written in TypeScript.

Current auto-completion is also based on Monaco Editor’s TypeScript features.

MongoDB

Example query:

typescript
mongoshell((db) => {
  db.collection("user").find().limit(12).skip(1);
});

INFO

mongoshell(db => {}) is auto-filled when the editor opens, no need to type it manually.

INFO

The function can also be asynchronous.

You can define multiple commands, and use parameters within them:

typescript
mongoshell((db) => {
  db.collection("user").find().limit(params.int("limit")).skip(1);
});

Redis

Example query:

typescript
redisshell((cli) => {
  cli.scan(0).stream();
});

You can also define multiple commands and use parameters.

For all scan commands, a .stream() method is available for auto-loading data as the table scrolls.

Some commands support extra options. For example, this scans all keys with memory usage >= 56:

typescript
redisshell((cli) => {
  cli.scan(0, { memory: 56 }).stream();
});

redis-big-key-sacn

Parameters

You can define parameters in MongoDB/Redis commands, like this:

typescript
mongoshell((db) => {
  db.collection("user").find(
    {name: { $regexp: params.string("name regexp") }}
  ).limit(
    params.int("limit")
  );
});

The params type is defined as:

typescript
declare const params: Params;

interface Param { name: string; }

declare class Params {
    int(name: string, opts?: {
        max?: number;
        min?: number;
        default?: number;
        nullable?: boolean;
    }): number;
    number(name: string, opts?: {
        max?: number;
        min?: number;
        default?: number;
        nullable?: boolean;
    }): number;
    float(name: string, opts?: {
        max?: number;
        min?: number;
        default?: number;
        nullable?: boolean;
    }): number;
    string(name: string, opts?: {
        default?: number;
        nullable?: boolean;
        regexp?: RegExp;
    }): string;
    datetime(name: string, opts?: {
        min?: string | Date;
        max?: string | Date;
        default?: number;
        nullable?: boolean;
        layout?: string;
        timezone?: string;
    }): Date;
}

Other APIs

Other available objects:

typescript
interface IObjectId {
 	toString(): string;
 	toHexString(): string;
}

// For Base64 encoding/decoding:
declare class Base64 {
	static encode(input: Uint8Array): string;
	static decode(input: string): Uint8Array;
}

// For generating ObjectId:
// ObjectId();
// ObjectId("650555814b47771608479999");
// ObjectId(1234567890);
declare function ObjectId(inputId?: string | number | IObjectId): IObjectId;

// For making HTTP requests.
// Useful for building dynamic query commands via custom APIs.
declare function http(method: string, url: string, opts?: { headers?: { [k: string]: string[] }; timeouts?: number; proxy?: string; body?: ["file", string] | Uint8Array }): Promise<{
	code: number;
	message: string;
	headers: { [k: string]: string[] };
	body: Uint8Array;
}>;