@mongodb-js/compass-aggregations
Compass Aggregation Pipeline Builder
Last updated 2 months ago by rhysm .
Apache-2.0 · Original npm · Tarball · package.json
$ cnpm install @mongodb-js/compass-aggregations 
SYNC missed versions from official npm registry.

compass-aggregations

Compass Plugin for the MongoDB Aggregation Pipeline Builder.

Code Tour

  • src/components/aggregations The primary export is connected component
  • src/modules/ is where action happens
    • action creators components call
    • reducers that call dataService, window.open, emit to other plugins, etc.
    • follows the ducks pattern
  • src/stores/store is where plugin listens+responds to events of interest from other plugins
  • store is global state instantiated via configureStore()
  • All tests are local to their module e.g. src/*/<module>.spec.js

Note: Cross-plugin Communication

How does clicking on export to language button in aggregation builder show the modal that has code in it?

The aggregation builder in Compass actually involves 2 Compass plugins:

Here's how these 2 plugins come together:

Usage with a mongodb-data-service Provider

See ./examples-data-service-provider.js for details on what data-service functions are used and the applicable options for each.

Examples

These are a base set of example aggregation's from @terakilobyte used in his M121 agg framework university course. These provide canonical, real-world references of various complexity for us to design/test against. The underlying source datasets are in Atlas and connected to a Stitch app (see examples/data-service-provider.js).

Basic

example-basic.js is a simple $match and $count.

View in storybook

Array Stats

example-array-stats.js uses $project of accumulators to generate summary statistics

View in storybook

Grouped Stats

example-grouped-stats.js uses $match and $group to achieve the same goal as example-array-stats.js

View in storybook

Schema Checker

example-complex.js uses $lookup and more to sanity check mistyped names or bad references.

View in storybook

Pearson's rho

example-pearsons-rho.js calculates the correlation co-efficient of two fields using Pearsons Rho. (HT @johnlpage)

View in storybook

Registering Examples

See aggregations.stories.js.

Adding new examples

  1. Put your data set in MongoDB Atlas
  2. Create a new Stitch app with read permissions for the example collection
  3. Copy ./example-grouped-stats.js to ./example-<my-example>.js and update with your pipeline details and stitchAppId
  4. In aggregations.stories.js import MY_EXAMPLE from ./example-<my-example>.js and add a new story
  5. npm run storybook and your new example will load
  6. Open a new pull request with your changes and include a brief description of what you use this aggregation pipeline for.

Contributing

If you're interested in helping with the Aggregation Builder plugin, we'd be over the moon excited! Here are a few ideas if you're interested but not sure where to start:

  • Add a new example aggregation
  • Additions/clarifications/improvements to README's
  • More tests (especially edge cases!)
  • Generate jsdoc html to include in GitHub pages
  • Improve build times (e.g. audit our webpack configs)

Related

Usage

This plugin uses an instance of a Redux store and not the traditional singleton, so the store instance must be passed to the plugin. The plugin exports a function to initialise the store instance, which decorates it with various methods to conveniently set any values it uses.

This is for:

  • @mongodb-js/compass-aggregations 4.0.0-beta.11
  • @mongodb-js/compass-export-to-language 4.0.2

Browser

Setting values via configure:

import AppRegistry from 'hadron-app-registry';
import AggregationsPlugin, {
  configureStore as configureAggregationsStore
} from '@mongodb-js/compass-aggregations';
import ExportToLanguagePlugin, {
  configureStore as configureExportToLanguageStore
} from '@mongodb-js/compass-export-to-language';

const handleOut = (namespace) => {
  window.open(`https://cloud.mongodb.com/${namespace}`, '_new');
};

const handleCopy = (query) => {
  alert(query);
};

const appRegistry = new AppRegistry();

const aggregationsStore = configureAggregationsStore({
  dataProvider: {
    error: null,
    dataProvider: dataProvider
  },
  namespace: 'db.coll',
  serverVersion: '4.2.0',
  fields: [],
  isAtlasDeployed: true,
  allowWrites: false,
  outResultsFn: handleOut,
  env: 'atlas',
  localAppRegistry: appRegistry
});

const exportToLanguageStore = configureExportToLanguageStore({
  localAppRegistry: appRegistry,
  copyToClipboardFn: handleCopy
});

<AggregationsPlugin store={aggregationsStore} />
<ExportToLanguagePlugin store={exportToLanguageStore} />

Hadron/Electron

const role = appRegistry.getRole('Collection.Tab')[0];
const Plugin = role.component;
const configureStore = role.configureStore;
const store = configureStore({
  globalAppRegistry: appRegistry,
  localAppRegistry: localAppRegistry,
  dataProvider: {
    error: null,
    dataProvider: dataProvider
  },
  env: 'on-prem',
  namespace: 'db.coll',
  serverVersion: '4.2.0',
  fields: []
});

<Plugin store={store} />

Fields

The fields array must be an array of objects that the ACE editor autocompleter understands. See This example for what that array looks like.

Data Provider

The data provider is an object that must adhere to the following interface:

/**
 * Get a count of documents.
 *
 * @param {String} namespace - The namespace in "db.collection" format.
 * @param {Object} filter - The MQL query filter.
 * @param {Object} options - The query options.
 * @param {Function} callback - Gets error and integer count as params.
 */
provider.count(namespace, filter, options, callback);

/**
 * Execute an aggregation pipeline.
 *
 * @param {String} namespace - The namespace in "db.collection" format.
 * @param {Array} pipeline - The pipeline.
 * @param {Object} options - The agg options.
 * @param {Function} callback - Gets error and cursor as params. Cursor must
 *   implement #toArray (which takes a callback with error and an array of result docs)
 *   and #close
 */
provider.aggregate(namespace, pipeline, options, callback);

App Registry Events Emmitted

Various actions within this plugin will emit events for other parts of the application can be listened to via hadron-app-registry. Local events are scoped to a Tab. Global events are scoped to the whole Compass application.

Global

  • 'open-create-view': Indicated Create View is to be opened.
  • 'compass:export-to-language:opened', source: Indicates export-to-language was opened. source refers to the module it is opened from, in this case Aggregations.
  • 'compass:aggregations:pipeline-imported': Indicates a pipeline ws imported, either from pasting the pipeline in, or from using the import functionality. Sends data to metrics.
  • 'compass:aggregations:create-view', numOfStages: Indicates Create View was successful. numOfStages refers to pipeline length. Sends data to metrics.
  • 'compass:aggregations:pipeline-opened': Indicates a saved pipeline was opened. Sends pipeline data to metrics.
  • 'open-namespace-in-new-tab': Indicates current pipeline's namespace is to be opened in a new tab. Called when Create View is successful, when $merge are to be shown, when $out results are to be shown.
  • 'compass:aggregations:update-view', numOfStages: Indicates a pipeline view was updated. numOfStages refers to the length of the pipeline. Sends data to metrics.
  • 'compass:aggregations:settings-applied', settings: Indicates pipeline settings are to be applied. settings include: isExpanded, isCommentMode, isDirty, sampleSize, maxTimeMS, limit.
  • 'refresh-data': Indicates a data refresh is required within Compass.
  • 'select-namespace', metadata: Indicates a namespace is being selected. Emitted when updating a collection. metadata refers to information about the pipeline.
  • 'agg-pipeline-deleted': Indicates a pipeline was deleted. Sends pipeline data to metrics.
  • 'agg-pipeline-saved', pipelineName: Indicates a pipeline was saved locally. Sens pipeline data to analytics.
  • 'agg-pipeline-executed', metadata: Indicates a pipeline was executed. metadata refers to data about the pipeline. Sends pipeline data to metrics.
  • 'agg-pipeline-out-executed', pipelineId: Indicates a pipeline was executed with a $out. Sends pipeline data to metrics.

Local

  • 'open-aggregation-export-to-language', pipeline: Indicates export-to-language plugin is to opened. pipeline refers to the pipeline to be exported.
  • 'open-create-view', { meta: { source, pipeline }}: Indicates Create View is being opened.

App Registry Events Received

Local

  • 'import-finished': When import data was successful, refresh plugin's input data.
  • 'fields-changed', fields: Received when schema fields change. Updates plugin's fields.
  • 'refresh-data': Received when Compass data was refreshed. Refreshes input data in the plugin.
  • 'open-create-view', { meta: { source, pipeline }}: Received when Create View is to be opened. Opens a Create View modal.

Global

  • 'refresh-data': Received when Input data is to be refreshed on Compass level. Refreshes plugin's input.

Metrics Events

  • refresh-data
  • open-create-view
  • agg-pipeline-saved
  • agg-pipeline-deleted
  • agg-pipeline-executed
  • agg-pipeline-out-executed
  • compass:aggregations:update-view
  • compass:aggregations:create-view
  • compass:aggregations:pipeline-opened
  • compass:aggregations:settings-applied
  • compass:aggregations:pipeline-imported

Development

Tests

npm run test

Electron

npm start

Storybook

npm run storybook

Analyze Build

npm run analyze

Install

npm i -S @mongodb-js/compass-aggregations

License

Apache 2.0

Current Tags

  • 7.1.6                                ...           latest (2 months ago)

259 Versions

  • 7.1.6                                ...           2 months ago
  • 7.1.5                                ...           2 months ago
  • 7.1.4                                ...           4 months ago
  • 7.1.3                                ...           5 months ago
  • 7.1.2                                ...           7 months ago
  • 7.1.1                                ...           7 months ago
  • 7.1.0                                ...           7 months ago
  • 7.0.4                                ...           7 months ago
  • 6.1.6                                ...           7 months ago
  • 7.0.3                                ...           8 months ago
  • 7.0.2                                ...           8 months ago
  • 7.0.1                                ...           8 months ago
  • 7.0.0                                ...           8 months ago
  • 6.1.5                                ...           9 months ago
  • 6.1.4                                ...           9 months ago
  • 6.1.3                                ...           9 months ago
  • 6.1.2                                ...           9 months ago
  • 6.1.1                                ...           9 months ago
  • 6.1.0                                ...           9 months ago
  • 6.0.4                                ...           10 months ago
  • 6.0.3                                ...           a year ago
  • 6.0.2                                ...           a year ago
  • 6.0.0                                ...           a year ago
  • 5.0.3                                ...           a year ago
  • 5.0.2                                ...           a year ago
  • 5.0.1                                ...           a year ago
  • 5.0.0                                ...           a year ago
  • 4.2.4                                ...           a year ago
  • 4.2.3                                ...           a year ago
  • 4.2.2                                ...           a year ago
  • 4.2.1                                ...           a year ago
  • 4.1.1                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.0.15                                ...           a year ago
  • 4.0.14                                ...           a year ago
  • 4.0.13                                ...           a year ago
  • 4.0.12                                ...           a year ago
  • 4.0.10                                ...           a year ago
  • 4.0.8                                ...           a year ago
  • 4.0.7                                ...           a year ago
  • 4.0.6                                ...           a year ago
  • 4.0.5                                ...           a year ago
  • 4.0.4                                ...           a year ago
  • 4.0.3                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 4.0.0-rc.7                                ...           a year ago
  • 4.0.0-rc.6                                ...           a year ago
  • 3.4.13                                ...           a year ago
  • 3.4.12                                ...           a year ago
  • 3.4.11                                ...           a year ago
  • 4.0.0-rc.5                                ...           a year ago
  • 3.4.10                                ...           a year ago
  • 4.0.0-rc.3                                ...           a year ago
  • 4.0.0-rc.2                                ...           a year ago
  • 4.0.0-rc.1                                ...           a year ago
  • 4.0.0-rc.0                                ...           a year ago
  • 4.0.0-beta.10                                ...           a year ago
  • 4.0.0-beta.9                                ...           a year ago
  • 4.0.0-beta.8                                ...           a year ago
  • 4.0.0-beta.7                                ...           a year ago
  • 3.4.9                                ...           a year ago
  • 4.0.0-beta.6                                ...           a year ago
  • 4.0.0-beta.5                                ...           a year ago
  • 4.0.0-beta.4                                ...           a year ago
  • 4.0.0-beta.3                                ...           a year ago
  • 4.0.0-beta.2                                ...           a year ago
  • 3.4.8                                ...           a year ago
  • 3.4.7                                ...           a year ago
  • 3.4.6                                ...           a year ago
  • 3.4.5                                ...           a year ago
  • 3.4.4                                ...           a year ago
  • 3.4.3                                ...           a year ago
  • 3.4.2                                ...           a year ago
  • 3.4.1                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 4.0.0-beta.1                                ...           a year ago
  • 4.0.0-beta.0                                ...           a year ago
  • 3.3.1                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 4.0.0-alpha.10                                ...           2 years ago
  • 3.2.1                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 4.0.0-alpha.9                                ...           2 years ago
  • 4.0.0-alpha.8                                ...           2 years ago
  • 3.1.3                                ...           2 years ago
  • 3.1.2                                ...           2 years ago
  • 4.0.0-alpha.7                                ...           2 years ago
  • 4.0.0-alpha.6                                ...           2 years ago
  • 4.0.0-alpha.5                                ...           2 years ago
  • 4.0.0-alpha.4                                ...           2 years ago
  • 4.0.0-alpha.3                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.6                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 4.0.0-alpha.2                                ...           2 years ago
  • 4.0.0-alpha.1                                ...           2 years ago
  • 4.0.0-alpha.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.18                                ...           2 years ago
  • 2.2.17                                ...           2 years ago
  • 2.2.12-beta.0                                ...           2 years ago
  • 2.2.16                                ...           2 years ago
  • 2.2.15                                ...           2 years ago
  • 2.2.14                                ...           2 years ago
  • 2.2.13                                ...           2 years ago
  • 2.2.12                                ...           2 years ago
  • 2.2.11                                ...           2 years ago
  • 2.2.10                                ...           2 years ago
  • 2.2.9                                ...           2 years ago
  • 2.2.8                                ...           2 years ago
  • 2.2.7                                ...           2 years ago
  • 2.2.6                                ...           2 years ago
  • 2.2.5                                ...           2 years ago
  • 2.2.4                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.8.5                                ...           2 years ago
  • 1.8.4                                ...           2 years ago
  • 1.8.3                                ...           2 years ago
  • 1.8.2                                ...           2 years ago
  • 1.8.1                                ...           2 years ago
  • 1.8.0                                ...           2 years ago
  • 1.7.2                                ...           2 years ago
  • 1.7.1                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.5                                ...           2 years ago
  • 1.6.4                                ...           2 years ago
  • 1.6.3                                ...           2 years ago
  • 1.6.2                                ...           2 years ago
  • 1.6.1                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.5.36                                ...           2 years ago
  • 1.5.35                                ...           2 years ago
  • 1.5.34                                ...           2 years ago
  • 0.2.38                                ...           2 years ago
  • 1.5.33                                ...           2 years ago
  • 0.2.37                                ...           2 years ago
  • 1.5.32                                ...           2 years ago
  • 1.5.31                                ...           2 years ago
  • 0.2.36                                ...           2 years ago
  • 1.5.30                                ...           2 years ago
  • 0.2.35                                ...           2 years ago
  • 1.5.29                                ...           2 years ago
  • 0.2.34                                ...           2 years ago
  • 0.2.33                                ...           2 years ago
  • 1.5.28                                ...           2 years ago
  • 0.2.32                                ...           2 years ago
  • 0.2.31                                ...           2 years ago
  • 0.2.30                                ...           2 years ago
  • 0.2.29-demo.2                                ...           2 years ago
  • 0.2.29-demo                                ...           2 years ago
  • 1.5.27                                ...           2 years ago
  • 1.5.26                                ...           2 years ago
  • 1.5.25                                ...           2 years ago
  • 1.5.24                                ...           2 years ago
  • 0.2.29                                ...           2 years ago
  • 1.5.23                                ...           2 years ago
  • 1.5.22                                ...           2 years ago
  • 1.5.21                                ...           2 years ago
  • 1.5.20                                ...           2 years ago
  • 1.5.19                                ...           2 years ago
  • 0.2.28                                ...           2 years ago
  • 1.5.18                                ...           2 years ago
  • 1.5.17                                ...           2 years ago
  • 0.2.27                                ...           2 years ago
  • 1.5.16                                ...           2 years ago
  • 0.2.26                                ...           2 years ago
  • 0.2.25                                ...           2 years ago
  • 1.5.15                                ...           2 years ago
  • 0.2.24                                ...           2 years ago
  • 0.2.23                                ...           2 years ago
  • 1.5.14                                ...           2 years ago
  • 1.5.13                                ...           2 years ago
  • 1.5.12                                ...           2 years ago
  • 1.5.11                                ...           2 years ago
  • 0.2.22                                ...           2 years ago
  • 0.2.20                                ...           2 years ago
  • 1.5.10                                ...           2 years ago
  • 1.5.9                                ...           2 years ago
  • 1.5.8                                ...           2 years ago
  • 0.2.18                                ...           2 years ago
  • 1.5.7                                ...           2 years ago
  • 1.5.6                                ...           2 years ago
  • 1.5.5                                ...           2 years ago
  • 0.2.17                                ...           2 years ago
  • 0.2.16                                ...           2 years ago
  • 0.2.15                                ...           2 years ago
  • 1.5.4                                ...           2 years ago
  • 0.2.14                                ...           2 years ago
  • 0.2.13                                ...           2 years ago
  • 1.5.3                                ...           2 years ago
  • 0.2.12                                ...           2 years ago
  • 1.5.2                                ...           2 years ago
  • 0.2.11                                ...           2 years ago
  • 1.5.1                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 0.2.10                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.2.8                                ...           3 years ago
  • 0.2.7                                ...           3 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.31                                ...           3 years ago
  • 0.0.30                                ...           3 years ago
  • 0.0.29                                ...           3 years ago
  • 0.0.28                                ...           3 years ago
  • 0.0.27                                ...           3 years ago
  • 0.0.26                                ...           3 years ago
  • 0.0.25                                ...           3 years ago
  • 0.0.24                                ...           3 years ago
  • 0.0.23                                ...           3 years ago
  • 0.0.22                                ...           3 years ago
  • 0.0.21                                ...           3 years ago
  • 0.0.20                                ...           3 years ago
  • 0.0.19                                ...           3 years ago
  • 0.0.18                                ...           3 years ago
  • 0.0.17                                ...           3 years ago
  • 0.0.16                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.12                                ...           3 years ago
  • 0.0.11                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 4
Dependencies (19)
Dev Dependencies (101)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |