How to use mingo - 10 common examples

To help you get started, we’ve selected a few mingo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VulcanJS / Vulcan / packages / nova-lib / lib / mongo-redux.js View on Github external
Mongo.Collection.prototype.findInStore = function (store, selector = {}, options = {}) {
  const typeName = this.options && this.options.typeName;
  const docs = _.where(store.getState().apollo.data, {__typename: typeName})
  
  const mingoQuery = Mingo.Query(selector);

  const cursor = mingoQuery.find(docs);
  const sortedDocs = cursor.sort(options.sort).all();

  // console.log('// findRedux')
  // console.log("typeName: ", typeName)
  // console.log("selector: ", selector)
  // console.log("options: ", options)
  // console.log("all docs: ", docs)
  // console.log("selected docs: ", cursor.all())
  // console.log("sorted docs: ", cursor.sort(options.sort).all())

  return {fetch: () => sortedDocs};
}
github LessWrong2 / Lesswrong2 / packages / vulcan-core / lib / modules / containers / withList.js View on Github external
// if collection has no mutations defined, just return previous results
  if (!collection.options.mutations) {
    return previousResults;
  }

  const newMutationName = collection.options.mutations.new && collection.options.mutations.new.name;
  const editMutationName = collection.options.mutations.edit && collection.options.mutations.edit.name;
  const removeMutationName = collection.options.mutations.remove && collection.options.mutations.remove.name;

  let newResults = previousResults;

  // get mongo selector and options objects based on current terms
  const result = collection.getParameters(mergedTerms, apolloClient);
  const { selector, options } = result;

  const mingoQuery = Mingo.Query(selector);

  // function to remove a document from a results object, used by edit and remove cases below
  const removeFromResults = (results, document) => {
    const listWithoutDocument = results[listResolverName].filter(doc => doc._id !== document._id);
    const newResults = update(results, {
      [listResolverName]: { $set: listWithoutDocument }, // ex: postsList
      [totalResolverName]: { $set: results[totalResolverName] - 1 } // ex: postsListTotal
    });
    return newResults;
  }

  // add document to a results object
  const addToResults = (results, document) => {

    return update(results, {
      [listResolverName]: { $unshift: [document] },
github Stellarium / stellarium-web-engine / web-frontend / src / assets / noctuasky-client.js View on Github external
// Stellarium Web - Copyright (c) 2018 - Noctua Software Ltd
//
// This program is licensed under the terms of the GNU AGPL v3, or
// alternatively under a commercial licence.
//
// The terms of the AGPL v3 license can be found in the main directory of this
// repository.

import Swagger from 'swagger-client'
import _ from 'lodash'
import store from 'store'
import mingo from 'mingo'

mingo.setup({key: 'id'})

var swaggerClient
var localIdCounter = 0

var generateLocalId = function () {
  localIdCounter++
  return 'local_' + localIdCounter
}

var equipments = [
  {
    id: 'none'
  },
  {
    id: 'base',
    schema: [
github TryGhost / GQL / test / query_json_spec.js View on Github external
const makeQuery = (gqlString) => {
    const filter = gql.parse(gqlString);
    return new mingo.Query(filter);
};
github joshmarinacci / idealos / proto1 / server / livedb.js View on Github external
evalScript(scr,doc,mode) {
        if(!scr.active) return;
        if(scr.language !== 'javascript') return;


        let mq = new mingo.Query(scr.trigger);
        const matched = mq.find([doc]).all();
        if(matched.length <= 0) return;
        console.log("found a script to trigger",scr);

        console.log('evaluating script ',scr.code);
        console.log('on document',doc);

        const event = {
            mode: mode,
            document: doc,
            database: this
        };

        try {
            //the actual eval
            eval(scr.code)(event);
github NexesJS / NQL / lib / nql.js View on Github external
api.queryJSON = function (obj) {
        this.query = this.query || new mingo.Query(api.parse());
        return this.query.test(obj);
    };
github VulcanJS / Vulcan / packages / vulcan-core / lib / modules / containers / cacheUpdate.js View on Github external
export const matchSelector = (document, selector) => {
    const mingoQuery = new Mingo.Query(selector);
    return mingoQuery.test(document);
};
github creately / rxdata / src / doc-utilities / filter-documents.ts View on Github external
export const createFilterFunction = (filter: any): Function => {
  const query = new Mingo.Query(filter);
  return (doc: any) => query.test(doc);
};
github creately / rxdata / src / collection.ts View on Github external
public watch(selector?: Selector): Observable> {
    if (!selector) {
      return this.changes.asObservable();
    }
    const mq = new mingo.Query(selector);
    return this.changes.pipe(
      switchMap(change => {
        const docs = change.docs.filter(doc => mq.test(doc));
        if (!docs.length) {
          return empty();
        }
        return of(Object.assign({}, change, { docs }));
      })
    );
  }
github creately / rxdata / src / collection.ts View on Github external
protected filter(docs: T[], selector: Selector, options: FindOptions): T[] {
    let cursor = mingo.find(docs, selector);
    if (options.sort) {
      cursor = cursor.sort(options.sort);
    }
    if (options.skip) {
      cursor = cursor.skip(options.skip);
    }
    if (options.limit) {
      cursor = cursor.limit(options.limit);
    }
    return cursor.all();
  }

mingo

MongoDB query language for in-memory objects

MIT
Latest version published 1 day ago

Package Health Score

83 / 100
Full package analysis