mingo
- Version 6.7.1
- Published
- 1.04 MB
- No dependencies
- MIT license
Install
npm i mingo
yarn add mingo
pnpm add mingo
Overview
MongoDB query language for in-memory objects
Index
Variables
variable _default
const _default: { Aggregator: typeof Aggregator; Context: typeof Context; ProcessingMode: typeof ProcessingMode; Query: typeof Query; aggregate: typeof aggregate; createUpdater: typeof createUpdater; find: typeof find; update: import('./updater').Updater;};
variable update
const update: Updater;
Updates the given object with the expression.
Parameter obj
The object to update.
Parameter expr
The update expressions.
Parameter arrayFilters
Filters to apply to nested items.
Parameter conditions
Conditions to validate before performing update.
Parameter options
Update options to override defaults.
Returns
{string[]} A list of modified field paths in the object.
Functions
function aggregate
aggregate: ( collection: Source, pipeline: AnyObject[], options?: Partial<Options>) => AnyObject[];
Performs an aggregation operation on the provided collection using the specified pipeline.
Parameter collection
The input data source to aggregate.
Parameter pipeline
An array of aggregation stages to process the collection.
Parameter options
Optional settings to customize the aggregation behavior.
Returns
The result of the aggregation as an array of objects.
function createUpdater
createUpdater: (defaultOptions?: UpdateOptions) => Updater;
Creates a new updater function with default options.
Parameter defaultOptions
The default options. Defaults to no cloning with strict mode off for queries.
Returns
{Updater}
function find
find: <T>( collection: Source, criteria: AnyObject, projection?: AnyObject, options?: Partial<Options>) => Cursor<T>;
Finds documents in a collection that match the specified criteria.
T - The type of the documents in the collection.
Parameter collection
The source collection to search.
Parameter criteria
The query criteria to filter the documents.
Parameter projection
Optional. Specifies the fields to include or exclude in the returned documents.
Parameter options
Optional. Additional options to customize the query behavior.
Returns
A
Cursor
object that allows iteration over the matching documents.
Classes
class Aggregator
class Aggregator extends AggregatorImpl {}
The
Aggregator
class provides functionality to process data collections through an aggregation pipeline. It supports streaming and executing aggregation operations with customizable options.
constructor
constructor(pipeline: AnyObject[], options?: Partial<Options>);
Creates an instance of the Aggregator class.
Parameter pipeline
An array of objects representing the aggregation pipeline stages.
Parameter options
Optional configuration settings for the aggregator.
class Context
class Context {}
method addAccumulatorOps
addAccumulatorOps: (ops: AccumulatorOps) => Context;
method addExpressionOps
addExpressionOps: (ops: ExpressionOps) => Context;
method addPipelineOps
addPipelineOps: (ops: PipelineOps) => Context;
method addProjectionOps
addProjectionOps: (ops: ProjectionOps) => Context;
method addQueryOps
addQueryOps: (ops: QueryOps) => Context;
method addWindowOps
addWindowOps: (ops: WindowOps) => Context;
method from
static from: (ctx?: Context) => Context;
method getOperator
getOperator: (type: OpType, name: string) => Callback | null;
method init
static init: (ops?: { accumulator?: AccumulatorOps; expression?: ExpressionOps; pipeline?: PipelineOps; projection?: ProjectionOps; query?: QueryOps; window?: WindowOps;}) => Context;
method merge
static merge: (first: Context, second: Context) => Context;
class Query
class Query extends QueryImpl {}
Represents a query object used to filter and match documents based on specified criteria. All query, projection, and related expression operators are preloaded into the context by default.
Example 1
const query = new Query({ age: { $gt: 18 } });const result = query.test({ name: "John", age: 25 }); // true
constructor
constructor(condition: AnyObject, options?: Partial<Options>);
Creates an instance of the query with the specified condition and options. This object is preloaded with all query and projection operators.
Parameter condition
The query condition object used to define the criteria for matching documents.
Parameter options
Optional configuration settings to customize the query behavior.
Enums
enum ProcessingMode
enum ProcessingMode { CLONE_OFF = 0, CLONE_INPUT = 1, CLONE_OUTPUT = 2, CLONE_ALL = 3,}
Enum representing the processing modes for handling input and output documents. This determines whether cloning is applied to maintain immutability or ensure distinct object references.
member CLONE_ALL
CLONE_ALL = 3
Clone both input and output documents. Combines
CLONE_INPUT
andCLONE_OUTPUT
.
member CLONE_INPUT
CLONE_INPUT = 1
Clone input documents to maintain immutability of the original input.
member CLONE_OFF
CLONE_OFF = 0
Do not clone inputs or outputs. Resulting documents may share references. This is the default mode.
member CLONE_OUTPUT
CLONE_OUTPUT = 2
Clone output documents to ensure distinct objects without shared references.
Package Files (5)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/mingo
.
- Markdown[](https://www.jsdocs.io/package/mingo)
- HTML<a href="https://www.jsdocs.io/package/mingo"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3644 ms. - Missing or incorrect documentation? Open an issue for this package.