You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by garrensmith <gi...@git.apache.org> on 2015/11/18 11:28:33 UTC

[GitHub] couchdb-nmo pull request: Add Mango Query support

GitHub user garrensmith opened a pull request:

    https://github.com/apache/couchdb-nmo/pull/14

    Add Mango Query support

    Able to create and query mango index

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/garrensmith/couchdb-nmo mango

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-nmo/pull/14.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #14
    
----
commit 4d18f67a71115332503757ab4344c223cd81a9b0
Author: Garren Smith <ga...@gmail.com>
Date:   2015-11-18T10:18:00Z

    Add Mango Query support
    
    Able to create and query mango index

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46550107
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used \" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +      promise = query(cluster, dbname, selector);
    +    }
    +
    +    promise
    +    .then(resp => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(resp);
    +      } else {
    +        console.log(prettyjson.render(resp.docs));
    +      }
    +      resolve(resp);
    +    })
    +    .catch(err => {
    +      err.type = 'EUSAGE';
    --- End diff --
    
    no usage error from the user here if something throws during the execution


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47223819
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,98 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +        return;
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used \" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +
    +      if(!selector) {
    --- End diff --
    
    hmm when i now try to get the help when i want to create an index i get:
    
    ```
    (14:11:58) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone restaurants
    ERR! You have to wrap the selector in single quotes
    e.g nmo query anemone restaurants '{"selector": {"id": {"$gt":null}}}'
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-161642204
  
    i could not try the command, as the code does not transpile any more with babel 5 (npm run transpile), also tried to reinstall all modules... rebasing with master solved the problem


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46549680
  
    --- Diff: doc/cli/nmo-query ---
    @@ -0,0 +1,17 @@
    +nmo-query(1) -- Query Mango
    +===========================================
    +
    +## SYNOPSIS
    +
    +    nmo query cluster database create <fields> [--json]
    +    nmo query cluster database selector [--json]
    --- End diff --
    
    ```
        nmo query <cluster> <database> create <fields> [--json]
        nmo query <cluster> <database> <selector> [--json]
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163600324
  
    not fixed yet: in case of something !== 200 we need an error message:
    
    ```
    (13:42:08) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone animaldb '{"selector": {"id": {"$gt":null}}}'
    http request POST http://127.0.0.1:15984/animaldb/_find
    http 404 http://127.0.0.1:15984/animaldb/_find
    ``` 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47223418
  
    --- Diff: doc/api/nmo-query.md ---
    @@ -0,0 +1,27 @@
    +nmo-query(3) -- Create Mango indexes or query existing ones
    +====================================================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.query([<clusterurl> || <cluster>], <database>, selector)
    +    nmo.commands.create([<clusterurl> || <cluster>], <database>, [fields])
    --- End diff --
    
    both commands are not exported in this way:
    
    ```
    > n.default.commands
    { isonline: [Function: isonline],
      help: [Function: help],
      config:
       { load: [Function: load],
         set: [Function: set],
         cli: [Function: cli],
         get: [Function: get],
         cliGet: [Function: cliGet],
         handleResult: [Function: handleResult] },
      cluster:
       { cli: [Function: cli],
         join: [Function: join],
         add: [Function: add],
         get: [Function: get] },
      v: [Function: version],
      'import-csv': [Function: importcsv],
      'couch-config':
       { cli: [Function: cli],
         getClusterNodes: [Function: getClusterNodes],
         get: [Function: get],
         set: [Function: set],
         setConfig: [Function: setConfig],
         buildConfigUrl: [Function: buildConfigUrl],
         getConfig: [Function: getConfig] },
      activetasks: [Function: getActiveTask],
      savetofile: [Function: savetofile],
      'replicate-from': [Function: replicateFrom],
      'replicate-to': [Function: replicateto],
      query:
       { cli: [Function: cli],
         query: [Function: query],
         create: [Function: create] } }
    
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-162876803
  
    in case of something !== 200 i probably want an error:
    
    ```
    (14:16:50) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone restaurants '{id: {"$gt":null}}'
    http request POST http://127.0.0.1:15984/restaurants/_find
    http 400 http://127.0.0.1:15984/restaurants/_find
    ```
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-162880248
  
    maybe we can fix the need for single quotes?
    
    ```
    ./bin/nmo-cli.js query anemone restaurants {"selector": {"_id": {"$gt":null}}}
    ERR! argument must be an object
    ERR! AssertionError: argument must be an object
    ```
    
    what do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-169273500
  
    hey garren, this looks really good now. 
    
    cool that you are going to fix all commands in a separate PR, with that: +1 :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47221184
  
    --- Diff: doc/api/nmo-query.md ---
    @@ -0,0 +1,27 @@
    +nmo-query(3) -- Create Mango indexes or query existing ones
    +====================================================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.query([<clusterurl> || <cluster>], <database>, selector)
    --- End diff --
    
    selector is required?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-162877476
  
    leaving one argument off:
    ```
    (14:19:45) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone restaurants
    ERR! argument must be an object
    ERR! AssertionError: argument must be an object
    ERR!     at /Users/robert/apache/couchdb-nmo/lib/utils.js:70:22
    ERR!     at Promise._execute (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/debuggability.js:159:9)
    ERR!     at Promise._resolveFromExecutor (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:460:18)
    ERR!     at new Promise (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:76:14)
    ERR!     at sendJsonToNode (/Users/robert/apache/couchdb-nmo/lib/utils.js:69:10)
    ERR!     at /Users/robert/apache/couchdb-nmo/lib/query.js:86:31
    ERR!     at Promise._execute (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/debuggability.js:159:9)
    ERR!     at Promise._resolveFromExecutor (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:460:18)
    ERR!     at new Promise (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:76:14)
    ERR!     at query (/Users/robert/apache/couchdb-nmo/lib/query.js:84:10)
    ERR!     at /Users/robert/apache/couchdb-nmo/lib/query.js:65:17
    ERR!     at Promise._execute (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/debuggability.js:159:9)
    ERR!     at Promise._resolveFromExecutor (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:460:18)
    ERR!     at new Promise (/Users/robert/apache/couchdb-nmo/node_modules/bluebird/js/release/promise.js:76:14)
    ERR!     at cli (/Users/robert/apache/couchdb-nmo/lib/query.js:31:10)
    ERR!     at /Users/robert/apache/couchdb-nmo/bin/nmo-cli.js:34:6
    ERR!
    ERR!
    ERR! nmo: 1.1.0 node: v4.2.1
    ERR! please open an issue including this log on https://github.com/robertkowalski/nmo/issues
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47223951
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,98 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    --- End diff --
    
    i don't get an ok if i create an index:
    
    ```
    (14:13:41) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone restaurants create foo
    http request POST http://127.0.0.1:15984/restaurants/_index
    http 200 http://127.0.0.1:15984/restaurants/_index
    
    (14:13:52) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $
    ```
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46953651
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || args.length === 0) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +        return;
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    --- End diff --
    
    maybe we can test for `/^}/.test(args0)` and then display some help to the user (something like:
    
    err.type = EUSAGE;
    err.message = Looks like you have forgotten to wrap the query in single quotesplease include quotes. Example usage: `nmo query anemone restaurants '{"selector": {"id": {"$gt":null}}}'`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46953362
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || args.length === 0) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +        return;
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    --- End diff --
    
    `args0` at this location in the code is then of type string `{selector:`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46953277
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || args.length === 0) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +        return;
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    --- End diff --
    
    here is how a query without quotes is handled internally:
    
    ```
    (14:36:58) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14 *) $ ./bin/nmo-cli.js query anemone restaurants {"selector": {"_id": {"$gt":null}}}
    { argv:
       { remain: [ 'anemone', 'restaurants', '{selector:', '{_id:', '{:null}}}' ],
         cooked:
          [ 'query',
            'anemone',
            'restaurants',
            '{selector:',
            '{_id:',
            '{:null}}}' ],
         original:
          [ 'query',
            'anemone',
            'restaurants',
            '{selector:',
            '{_id:',
            '{:null}}}' ] },
      nmoconf: '/Users/robert/.nmorc' }
    
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46549920
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    --- End diff --
    
    a return is missing here to stop execution


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163600985
  
    this one is affecting many of our new commands, maybe we write a small general helper for it (i think some commands [already use `isOnline` internally](https://github.com/apache/couchdb-nmo/blob/master/src/cluster.js#L56)):
    
    ```
    (13:41:53) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone animaldb '{"selector": {"id": {"$gt":null}}}'
    http request POST http://127.0.0.1:15984/animaldb/_find
    ERR! Client request error: connect ECONNREFUSED 127.0.0.1:15984
    ERR! Error: connect ECONNREFUSED 127.0.0.1:15984
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/couchdb-nmo/pull/14


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46549796
  
    --- Diff: package.json ---
    @@ -57,15 +57,15 @@
         "xtend"
       ],
       "devDependencies": {
    -    "babel": "^5.1.10",
    -    "babel-eslint": "^4.1.5",
    -    "eslint": "^1.9.0",
    -    "jshint": "^2.8.0",
    +    "babel": "~5.1.10",
    +    "babel-eslint": "~4.1.5",
    +    "eslint": "~1.9.0",
    +    "jshint": "~2.8.0",
         "lab": "~5.5.1",
         "lab-babel": "1.0.0",
         "less": "~2.5.0",
         "marked-man": "~0.1.4",
    -    "nock": "^2.10.0",
    +    "nock": "~2.10.0",
         "node-doc-generator": "robertkowalski/node-documentation-generator#sloppy"
    --- End diff --
    
    just curious, why switching from ~ to ^?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163603896
  
    sorry garren, some issues are not fixed yet :((


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163618100
  
    Thanks for testing. Very weird they not working. I'll take a look 
    
    All misspelling thanks to my iPhone
    
    > On 10 Dec 2015, at 2:59 PM, Robert Kowalski <no...@github.com> wrote:
    > 
    > sorry garren, some issues are not fixed yet :((
    > 
    > —
    > Reply to this email directly or view it on GitHub.
    > 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46947551
  
    --- Diff: package.json ---
    @@ -57,15 +57,15 @@
         "xtend"
       ],
       "devDependencies": {
    -    "babel": "^5.1.10",
    -    "babel-eslint": "^4.1.5",
    -    "eslint": "^1.9.0",
    -    "jshint": "^2.8.0",
    +    "babel": "~5.1.10",
    +    "babel-eslint": "~4.1.5",
    +    "eslint": "~1.9.0",
    +    "jshint": "~2.8.0",
         "lab": "~5.5.1",
         "lab-babel": "1.0.0",
         "less": "~2.5.0",
         "marked-man": "~0.1.4",
    -    "nock": "^2.10.0",
    +    "nock": "~2.10.0",
         "node-doc-generator": "robertkowalski/node-documentation-generator#sloppy"
    --- End diff --
    
    Sorry I'm not sure why I did this. Might have been by accident.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47222599
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,98 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query <cluster> <database> create <fields> [--json]',
    +        'nmo query <cluster> <database> <selector> [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +        return;
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used \" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +
    +      if(!selector) {
    +        const msg = [
    +          'You have to wrap the selector in single quotes',
    +          'e.g nmo query anemone restaurants \'{"selector": {"id": {"$gt":null}}}\''
    --- End diff --
    
    if we provide the default "catch-all-selector" users have it easier:
    
    ```
    'e.g nmo query anemone restaurants \'{"selector": {"_id": {"$gt":null}}}\''
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163602802
  
    hm i can't get the command to work, also with an existing db:
    
    ```
    (13:51:19) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone restaurants '{"selector": {"id": {"$gt":null}}}'
    http request POST http://127.0.0.1:15984/restaurants/_find
    http 400 http://127.0.0.1:15984/restaurants/_find
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46549583
  
    --- Diff: doc/api/nmo-query.md ---
    @@ -0,0 +1,27 @@
    +nmo-query(3) -- Create Mango indexes or query existing ones
    +====================================================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.query([<clusterurl> || <cluster>], database, selector)
    +    nmo.commands.create([<clusterurl> || <cluster>], database, [fields])
    --- End diff --
    
    database is required


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46947780
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used \" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +      promise = query(cluster, dbname, selector);
    +    }
    +
    +    promise
    +    .then(resp => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(resp);
    +      } else {
    +        console.log(prettyjson.render(resp.docs));
    +      }
    +      resolve(resp);
    +    })
    +    .catch(err => {
    +      err.type = 'EUSAGE';
    --- End diff --
    
    I'm not quite sure what you mean here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46549826
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    --- End diff --
    
        nmo query <cluster> <database> create <fields> [--json]
        nmo query <cluster> <database> <selector> [--json]


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r47223636
  
    --- Diff: doc/api/nmo-query.md ---
    @@ -0,0 +1,27 @@
    +nmo-query(3) -- Create Mango indexes or query existing ones
    +====================================================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.query([<clusterurl> || <cluster>], <database>, selector)
    +    nmo.commands.create([<clusterurl> || <cluster>], <database>, [fields])
    --- End diff --
    
    it would be:
    
    ```
    nmo.commands.query.create
    nmo.commands.query.query
    ```
    
    maybe better names are:
    
    ```
    nmo.commands.query.run
    nmo.commands.query.createindex
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46952143
  
    --- Diff: doc/cli/nmo-query ---
    @@ -0,0 +1,17 @@
    +nmo-query(1) -- Query Mango
    +===========================================
    +
    +## SYNOPSIS
    +
    +    nmo query cluster <database> create <fields> [--json]
    +    nmo query cluster <database> <selector> [--json]
    +
    +## DESCRIPTION
    +
    +Create and query CouchDB Mango indexes.
    +
    +This will create an index with three fields
    +    nmo query mycluster database create name surname age
    +
    +This will query an index
    +    nmo query mycluster database {name: "Harry", age: {$gt: 5}, surname: {gt: null}}
    --- End diff --
    
    i think a selector is missing here:
    
    ```
    nmo query mycluster database {"selector": {"_id": {"$gt":null}}}
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-163601650
  
    this also affects most of our new commands - it happens when the db is not present...:
    
    ```
    (13:48:22) [robert@tequila-work] ~/apache/couchdb-nmo (pr/14) $ ./bin/nmo-cli.js query anemone animaldb '{"selector": {"id": {"$gt":null}}}'
    http request POST http://127.0.0.1:15984/animaldb/_find
    http 404 http://127.0.0.1:15984/animaldb/_find
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-168955347
  
    @robertkowalski I've made a few fixes. That should hopefully get it working properly now. I haven't done the online check. I will do that as a separate PR as I will apply it to all new commands.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46948360
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used \" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +      promise = query(cluster, dbname, selector);
    +    }
    +
    +    promise
    +    .then(resp => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(resp);
    +      } else {
    +        console.log(prettyjson.render(resp.docs));
    +      }
    +      resolve(resp);
    +    })
    +    .catch(err => {
    +      err.type = 'EUSAGE';
    --- End diff --
    
    i mean not every error is automatically a usage error. eusage is to help the user when they used the cli in a wrong way. but errors thrown here could also be just bugs when something throws, in this case we want the stacktrace with the small note "please copy this log and send it to the issue tracker"


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Add Mango Query support

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#issuecomment-162877081
  
    i was running this three times quite puzzled, then i spotted the 400 error code (which would go away if i set the loglevel to error or just listen on stderr)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---