<commit_before># mongoose-repl

A Mongo REPL with the full power of Mongoose.

If you're using the [Mongoose ODM](http://mongoosejs.com/) to keep your MongoDB code from descending into schema-less chaos, it can be a pain to fall back to the barebones Mongo shell when you want to interact with your data.

`mongoose-repl` registers your schemas and exposes the resulting models in an interactive REPL, so you can `findById` and `populate` to your heart's content. You'll never have to type `ObjectId` again. Oh, and did I mention it interprets CoffeeScript?

    $ mongoose --schemas examples/schemas.coffee localhost/test
    > Dog.findById('520bb7baa4e06dc4e9000001').select('enemy name').populate('enemy')
    { name: 'fido',
      enemy: { name: 'fluffy', _id: 520baec9d61fae3ee6000001, __v: 0 },
      _id: 520bb7baa4e06dc4e9000001 }
    > Cat.findById _.enemy._id
    { name: 'fluffy', _id: 520baec9d61fae3ee6000001, __v: 0 }

## Installation

    npm install -g mongoose-repl

## Usage

### Connecting to a DB

To connect to a Mongo instance, simply pass in a [MongoDB connection string](http://docs.mongodb.org/manual/reference/connection-string/):

    $ mongoose localhost/test 
    Connecting to: localhost
    Using db: test
    No models loaded
    >

Now we have access to the Mongoose connection object:

    > conn.host
    'localhost'
    > conn.name
    'test'
    > conn.db
    { domain: null,
      _events: 
       { close: [Function],
         error: [Function],
     ...

### Loading Models

Notice that no models were loaded, so the REPL isn't very useful yet. In order for `mongoose-repl` to give you access to Mongoose models, you have to first tell it about your schemas. Create a file that exports a mapping from schema names to schemas, like so:

    $ cat examples/schemas.coffee
```coffeescript
{Schema} = require 'mongoose'<commit_msg>README tweaks<commit_after># mongoose-repl

A Mongo REPL with the full power of Mongoose.

If you're using the [Mongoose ODM](http://mongoosejs.com/) to keep your MongoDB code from descending into schema-less chaos, it can be a pain to fall back to the barebones Mongo shell when you want to interact with your data.

`mongoose-repl` registers your schemas and exposes the resulting models in an interactive REPL, so you can `findById` and `populate` to your heart's content. You'll never have to type `ObjectId` again! Oh, and did I mention it interprets CoffeeScript?

    $ mongoose --schemas examples/schemas.coffee localhost/test
    > Dog.findById('520bb7baa4e06dc4e9000001').select('enemy name').populate('enemy')
    { name: 'fido',
      enemy: { name: 'fluffy', _id: 520baec9d61fae3ee6000001, __v: 0 },
      _id: 520bb7baa4e06dc4e9000001 }
    > Cat.findById _.enemy._id
    { name: 'fluffy', _id: 520baec9d61fae3ee6000001, __v: 0 }

## Installation

    npm install -g mongoose-repl

## Usage

### Connecting to a DB

To connect to a Mongo instance, simply pass in a [MongoDB connection string](http://docs.mongodb.org/manual/reference/connection-string/):

    $ mongoose localhost/test 
    Connecting to: localhost
    Using db: test
    No models loaded
    >

Now you have access to the Mongoose connection object:

    > conn.host
    'localhost'
    > conn.name
    'test'
    > conn.db
    { domain: null,
      _events: 
       { close: [Function],
         error: [Function],
     ...

### Loading Models

Notice that no models were loaded, so the REPL isn't very useful yet. In order for `mongoose-repl` to give you access to Mongoose models, you have to first tell it about your schemas. Create a module that exports a mapping from schema names to schemas, like so:

    $ cat examples/schemas.coffee
```coffeescript
{Schema} = require 'mongoose'
{'fraction_non_alphanumeric': 0.09044688252609044, 'fraction_numerical': 0.03211131924003211, 'mean_word_length': 3.4873949579831933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1477838', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1157, 'n_words': 442}