https://github.com/tj/node-monquery
mongodb query language for humans
https://github.com/tj/node-monquery
Last synced: 9 months ago
JSON representation
mongodb query language for humans
- Host: GitHub
- URL: https://github.com/tj/node-monquery
- Owner: tj
- Created: 2014-02-05T04:40:48.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-10-11T18:58:42.000Z (over 11 years ago)
- Last Synced: 2024-04-13T21:56:10.263Z (over 1 year ago)
- Language: JavaScript
- Size: 184 KB
- Stars: 106
- Watchers: 9
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# monquery
Lucene-inspired string-based mongodb query language for humans (and ferrets).
## Installation
```
$ npm install monquery
```
## Why?
1. Nicer UX for the odd search / log filtering
2. Writing JSON queries is a PITA
## Example
```js
var compile = require('monquery');
var str = 'level:error OR type:upload';
var query = compile(str);
```
## Querying
### Fields
Specify field names with optional values:
```js
level:error
```
yields
```js
{ level: 'error' }
```
### Booleans
Omit value to imply __true__:
```js
failed
```
yields
```js
{ failed: true }
```
Or specify a boolean-ish value (true, false, yes, no):
```js
failed: no
```
yields
```js
{ failed: false }
```
### Operators
Currently supports __AND__ / __OR__, which may be nested:
```js
(level:error AND type:"upload failed") OR user.name.first:Tobi
```
yields
```js
{ '$or':
[ { '$and': [ { level: 'error' }, { type: 'upload failed' } ] },
{ 'user.name.first': 'Tobi' } ] }
```
### Regular Expressions
Regexps may be used with the `//` syntax:
```js
level:info AND name:/^To/
```
yields
```js
{ '$and': [ { level: 'info' }, { name: /^To/ } ] }
```
### Patterns
Wildcards may be used to generate regular expressions:
```js
level:error AND hostname:api-*
```
yields
```js
{ '$and': [ { level: 'error' }, { hostname: /^api-.*$/ } ] }
```
# License
MIT