<commit_before># MongoDB Shell Enhancements for Hackers

## Warning

These enhancements are useful to me but they don't make sense for everyone. Feel free to tweak to your desire and please submit pull requests.

## Usage

Link mongo_hacker.js to `.mongorc.js` in your home directory:

```
ln -sf <mongo-hacker-dir>/mongo_hacker.js ~/.mongorc.js
```

Note: This currently only works with the v2.2+ of shell (which you can use with earlier versions of the server safely)

## List of Enhancements

### Basic

Verbose shell is enabled by default -- to disable: `setVerboseShell(false)`

Disable notfication of "Type 'it' for more"

Custom prompt with `hostname(process-version)>` formating

### Awesome

Colorized query output

![Colorized Output](http://tylerbrock.github.com/mongo-hacker/screenshots/colorized_shell.png)

- ObjectId: Green(underlined)
- null: Bright Red
- String: Green
- Number: Red
- Key: Yellow
- Boolean: Blue
- Date: Cyan

Highlight querytime if verboseShell is enabled
  - In **green** if querytime is at or below slowms
  - In **red** if query time is above slowms

![Colorized Quertime](http://tylerbrock.github.com/mongo-hacker/screenshots/querytime.png)

IndexParanoia
- Automatically show information about index use -- to disable: `setIndexParanoia(false)`

![Index Paranoia](http://tylerbrock.github.com/mongo-hacker/screenshots/index_paranoia.png)

Default indent is 2 spaces instead of tab
  - Customizable by setting `__indent`

AutoMulti
- Automatically use multi updates -- to disable: `setAutoMulti(false)`

``` js
db.users.update({}, {$set: {awesome: true}})
Updated 4 existing record(s) in 1ms
```

Aggregation Framework Helpers -- on collections
- Group and Count: `gcount(group_field, filter)`
- Group and Sum: `gsum(group_field, sum_field, filter)`

## Examples

### Insert some data

``` js
db.users.insert([
  {
    "age": 27,
    "first_name": "Tyler",
    "last_name": "Brock",
    "updated": new Date()
  },
  { 
    "age": 30,
    "first_name": "Jessica",
    "last_name": "Fake",
    "updated": new Date()
  },
  {
    "age": 35,
    "first_name": "Tyler",
    "last_name": "Durden",
    "updated": new Date()
  }
])
```

### Group and count users by the first_name field

``` js
db.users.gcount("first_name")
{
  "result": [
    {
      "_id": "Jessica",
      "count": 1
    },
    {
      "_id": "Tyler",
      "count": 2
    }
  ],
  "ok": 1
}
```

### Group and count users having first_name of Tyler

``` js
db.users.gcount("first_name", {first_name: "Tyler"})
{
  "result": [
    {
      "_id": "Tyler",
      "count": 2
    }
  ],
  "ok": 1
}
```

### Group users by first name and sum the age field

```js
db.users.gsum("first_name", "age")
{
  "result": [
    {
      "_id": "Jessica",
      "sum": 30
    },
    {
      "_id": "Tyler",
      "sum": 62
    }
  ],
  "ok": 1
}
```<commit_msg>Removing old screenshots from readme.<commit_after># MongoDB Shell Enhancements for Hackers

## Warning

These enhancements are useful to me but they don't make sense for everyone. Feel free to tweak to your desire and please submit pull requests.

## Usage

Link mongo_hacker.js to `.mongorc.js` in your home directory:

```
ln -sf <mongo-hacker-dir>/mongo_hacker.js ~/.mongorc.js
```

Note: This currently only works with the v2.2+ of shell (which you can use with earlier versions of the server safely)

## List of Enhancements

### Basic

Verbose shell is enabled by default -- to disable: `setVerboseShell(false)`

Disable notfication of "Type 'it' for more"

Custom prompt with `hostname(process-version)>` formating

### Awesome

Colorized query output

![Colorized Output](http://tylerbrock.github.com/mongo-hacker/screenshots/colorized_shell.png)

- ObjectId: Green(underlined)
- null: Bright Red
- String: Green
- Number: Red
- Key: Yellow
- Boolean: Blue
- Date: Cyan

Highlight querytime if verboseShell is enabled
  - In **green** if querytime is at or below slowms
  - In **red** if query time is above slowms

IndexParanoia
- Automatically show information about index use -- to disable: `setIndexParanoia(false)`

Default indent is 2 spaces instead of tab
  - Customizable by setting `__indent`

AutoMulti
- Automatically use multi updates -- to disable: `setAutoMulti(false)`

``` js
db.users.update({}, {$set: {awesome: true}})
Updated 4 existing record(s) in 1ms
```

Aggregation Framework Helpers -- on collections
- Group and Count: `gcount(group_field, filter)`
- Group and Sum: `gsum(group_field, sum_field, filter)`

## Examples

### Insert some data

``` js
db.users.insert([
  {
    "age": 27,
    "first_name": "Tyler",
    "last_name": "Brock",
    "updated": new Date()
  },
  { 
    "age": 30,
    "first_name": "Jessica",
    "last_name": "Fake",
    "updated": new Date()
  },
  {
    "age": 35,
    "first_name": "Tyler",
    "last_name": "Durden",
    "updated": new Date()
  }
])
```

### Group and count users by the first_name field

``` js
db.users.gcount("first_name")
{
  "result": [
    {
      "_id": "Jessica",
      "count": 1
    },
    {
      "_id": "Tyler",
      "count": 2
    }
  ],
  "ok": 1
}
```

### Group and count users having first_name of Tyler

``` js
db.users.gcount("first_name", {first_name: "Tyler"})
{
  "result": [
    {
      "_id": "Tyler",
      "count": 2
    }
  ],
  "ok": 1
}
```

### Group users by first name and sum the age field

```js
db.users.gsum("first_name", "age")
{
  "result": [
    {
      "_id": "Jessica",
      "sum": 30
    },
    {
      "_id": "Tyler",
      "sum": 62
    }
  ],
  "ok": 1
}
```
{'fraction_non_alphanumeric': 0.14832881662149955, 'fraction_numerical': 0.007588075880758808, 'mean_word_length': 3.311526479750779, 'pattern_counts': {'":': 56, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '580956', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1904, 'n_words': 586}