How to use the mingo.Query function in mingo

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 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 VulcanJS / Vulcan / packages / vulcan-lib / lib / client / apollo-client / updates.js View on Github external
export const reorderSet = (queryData, sort, selector) => {
  const mingoQuery = new Mingo.Query(selector);
  const cursor = mingoQuery.find(queryData.results);
  queryData.results = cursor.sort(sort).all();
  return queryData;
};
github VulcanJS / Vulcan / packages / vulcan-core / lib / modules / containers / cacheUpdate.js View on Github external
export const reorderSet = (results, sort, selector) => {
    const mingoQuery = new Mingo.Query(selector);
    const cursor = mingoQuery.find(results);
    const sortedResults = cursor.sort(sort).all();
    return sortedResults;
};

mingo

MongoDB query language for in-memory objects

MIT
Latest version published 2 days ago

Package Health Score

83 / 100
Full package analysis