mongodb-ace-autocompleter

Ace Editor Autocompleter for MongoDB Queries & Agg Pipelines


Keywords
MongoDB, Ace, ace-autocompleter, compass-ui-tools
License
Apache-2.0
Install
npm install mongodb-ace-autocompleter@0.4.4

Documentation

mongodb-ace-autocompleter

Provides MongoDB custom ACE Editor auto-completers

Usage

Aggregation Pipelines

Provides completions within the context of an individual aggregation pipeline stage:

import ace from 'ace-builds';
import { StageAutoCompleter } from 'mongodb-ace-autocompleter';

// Get the basic text completer from Ace for fallback suggestions.
import tools from 'ace-builds/src-noconflict/ext-language_tools';
const textCompleter = tools.textCompleter;

// For auto completion of agg pipeline stages, pass the server version,
// the text completer, the processed schema fields, and the stage operator.
const stageAutoCompleter = new StageAutoCompleter(
  '3.6.0',
  textCompleter,
  [{
    name: 'name',
    value: 'name',
    score: 1,
    meta: 'field',
    version: '0.0.0'
  }],
  '$match'
);
tools.setCompleters([ stageAutoCompleter ]);

Queries

Provides completions within the context of a find(query):

import ace from 'ace-builds';
import { QueryAutoCompleter } from 'mongodb-ace-autocompleter';

// Get the basic text completer from Ace for fallback suggestions.
import tools from 'ace-builds/src-noconflict/ext-language_tools';
const textCompleter = tools.textCompleter;

// For auto completion of queries, pass the server version,
// the text completer, and the processed schema fields
const queryAutoCompleter = new QueryAutoCompleter(
  '3.6.0',
  textCompleter,
  [{
    name: 'name',
    value: 'name',
    score: 1,
    meta: 'field',
    version: '0.0.0'
  }]
);
tools.setCompleters([ queryAutoCompleter ]);

Related

Misc

Utility function to convert from the fields returned from the field store to the Ace friendly format. (Can be done in a reducer in the app).

const process = (fields) => {
  return Object.keys(fields).map((key) => {
    const field = key.indexOf('.') > -1 ? `"${key}"` : key;
    return {
      name: key,
      value: field,
      score: 1,
      meta: 'field',
      version: '0.0.0'
    };
  });
};

Release

npm run release

License

Apache 2.0