Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

jamlfy/humanquery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HumanQuery

Lucene-inspired string-based mongodb query language for humans (and ferrets). And implemention in Mongoose

Installation

$ npm install humanquery

Why?

  1. Nicer UX for the odd search / log filtering
  2. Writing JSON queries is a PITA

Example

var mongoose = require('mongoose');
require('humanquery')( mongoose );

Query

model.findOne().query('level:error OR type:upload', function(err, doc){
  // More Code..
});
model.query('level:error OR type:upload').count(function(err, doc){
  // More Code..
});

Querying

Fields

Specify field names with optional values:

level:error

yields

{ level: 'error' }

Booleans

Omit value to imply true:

failed

yields

{ failed: true }

Or specify a boolean-ish value (true, false, yes, no):

failed: no

yields

{ failed: false }

Operators

Currently supports AND / OR, which may be nested:

(level:error AND type:"upload failed") OR user.name.first:Tobi

yields

{ '$or':
   [ { '$and': [ { level: 'error' }, { type: 'upload failed' } ] },
     { 'user.name.first': 'Tobi' } ] }

Regular Expressions

Regexps may be used with the // syntax:

level:info AND name:/^To/

yields

{ '$and': [ { level: 'info' }, { name: /^To/ } ] }

Patterns

Wildcards may be used to generate regular expressions:

level:error AND hostname:api-*

yields

{ '$and': [ { level: 'error' }, { hostname: /^api-.*$/ } ] }

License

MIT

About

Mongoose query language for humans

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published