All Projects โ†’ TylerBrock โ†’ Mongo Hacker

TylerBrock / Mongo Hacker

Licence: mit
MongoDB Shell Enhancements for Hackers

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to Mongo Hacker

Wertik Js
๐Ÿ’ช A library that powers your app with GraphQL + Rest API
Stars: โœญ 56 (-96.86%)
Mutual labels:  database, mongodb
Avocado
Strongly-typed MongoDB driver for Rust
Stars: โœญ 70 (-96.08%)
Mutual labels:  database, mongodb
Nodbi
Document DBI connector for R
Stars: โœญ 56 (-96.86%)
Mutual labels:  database, mongodb
Mongodb Interview Questions
MongoDB Interview Questions
Stars: โœญ 31 (-98.26%)
Mutual labels:  database, mongodb
Liiptestfixturesbundle
This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications
Stars: โœญ 92 (-94.85%)
Mutual labels:  database, mongodb
Mongo4idea
MongoDB integration in Intellij
Stars: โœญ 966 (-45.91%)
Mutual labels:  database, mongodb
Restfeel
RESTFeel: ไธ€ไธชไผไธš็บง็š„API็ฎก็†&ๆต‹่ฏ•ๅนณๅฐใ€‚RESTFeelๅธฎๅŠฉไฝ ่ฎพ่ฎกใ€ๅผ€ๅ‘ใ€ๆต‹่ฏ•ๆ‚จ็š„APIใ€‚
Stars: โœญ 59 (-96.7%)
Mutual labels:  database, mongodb
Migrate
Database migrations. CLI and Golang library.
Stars: โœญ 7,712 (+331.8%)
Mutual labels:  database, mongodb
Laravel Log To Db
Custom Laravel and Lumen 5.6+ Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel/Monolog native logging functionality.
Stars: โœญ 76 (-95.74%)
Mutual labels:  database, mongodb
Lxhive
A lightweight Experience API Learning Record Store (LRS)
Stars: โœญ 73 (-95.91%)
Mutual labels:  database, mongodb
Reactivemongo
๐Ÿƒ Non-blocking, Reactive MongoDB Driver for Scala
Stars: โœญ 825 (-53.81%)
Mutual labels:  database, mongodb
Meteor Peerdb
Reactive database layer with references, generators, triggers, migrations, etc.
Stars: โœญ 128 (-92.83%)
Mutual labels:  database, mongodb
Mongo Cxx Driver
C++ Driver for MongoDB
Stars: โœญ 792 (-55.66%)
Mutual labels:  database, mongodb
East
node.js database migration tool
Stars: โœญ 53 (-97.03%)
Mutual labels:  database, mongodb
Cocorico
๐Ÿ‘ Cocorico is an open source marketplace solution for services and rentals. More information right here: https://www.cocorico.io/en/ ๐Ÿš€ Cocorico is also available in an off-the-shelf SaaS package, check out https://www.hatch.li to launch your platform today. ๐Ÿ˜ We are hiring (telecommute welcome ๐Ÿก): https://www.welcometothejungle.com/en/companies/cocorico/jobs/candidatures-spontanees#apply
Stars: โœญ 765 (-57.17%)
Mutual labels:  database, mongodb
Docker Backup Database
Docker image to periodically backup your database (MySQL, Postgres, or MongoDB) to S3 or local disk.
Stars: โœญ 57 (-96.81%)
Mutual labels:  database, mongodb
Restheart
RESTHeart - The REST API for MongoDB
Stars: โœญ 659 (-63.1%)
Mutual labels:  database, mongodb
Blog
Everything about database,business.(Most for PostgreSQL).
Stars: โœญ 6,330 (+254.42%)
Mutual labels:  database, mongodb
Mongoaudit
๐Ÿ”ฅ A powerful MongoDB auditing and pentesting tool ๐Ÿ”ฅ
Stars: โœญ 1,174 (-34.27%)
Mutual labels:  database, mongodb
Databazel
The analytical and reporting solution for MongoDB
Stars: โœญ 118 (-93.39%)
Mutual labels:  database, mongodb
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚           __  ___                           __  __           __                   โ”‚
        โ”‚          /  |/  /___  ____  ____ _____     / / / /___ ______/ /_____  _____       โ”‚
        โ”‚         / /|_/ / __ \/ __ \/ __ `/ __ \   / /_/ / __ `/ ___/ //_/ _ \/ ___/       โ”‚
        โ”‚        / /  / / /_/ / / / / /_/ / /_/ /  / __  / /_/ / /__/ ,< /  __/ /           โ”‚
        โ”‚       /_/  /_/\____/_/ /_/\__, /\____/  /_/ /_/\__,_/\___/_/|_|\___/_/            โ”‚
        โ”‚                          /____/                                                   โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

MongoDB Shell Enhancements

Warnings

  • These enhancements are useful to me but they don't make sense for everyone. Feel free to tweak to your desire and please submit feedback or pull requests.
  • Only tested with non-EOL versions of MongoDB server (currently 3.4+)
  • Does not work with mongo shell or MongoDB servers < 2.4
  • Updates called on existing cursors are experimental (see notes in API section)

Installation

npm install -g mongo-hacker

Install from source

git clone https://github.com/TylerBrock/mongo-hacker
cd mongo-hacker
make install
cd ..
rm -rdf mongo-hacker/

Enhancements

Basic UX

  • Verbose shell is enabled by default (config: verbose_shell)
    • To toggle temporarily run setVerboseShell(false)
  • Highlight query time if verbose shell is enabled
    • In green if query time is at or below slowms
    • In red if query time is above slowms
  • Default indent is 2 spaces instead of tab (config: indent)
  • Disable notification of "Type 'it' for more"
  • Option to sort document keys (config: sort_keys)
  • Custom prompt: hostname(process-version)[rs_status:set_name] db>
  • Always pretty print. You can still use default format by appending .ugly() to the end of a statement.
  • Colorized query output for console/terminal windows supporting ANSI color codes. Colorized Output

Additional shell commands

The MongoDB shell offers various "shell commands" (sometimes referred to as "shell helpers" as well) that make interactive use of the shell much more convenient than proper, Javascript-only scripted use of the shell.

To make interactive use of the MongoDB shell even more convenient, mongo-hacker adds the following shell commands:

  • count collections/count tables: count the number of collections in each of the mongo server's databases
  • count documents/count docs: count the number of documents in all (non-system) collections in the database
  • count indexes: list all collections and display the size of all indexes

Some of these commands have hidden features that can be enabled in the mongo-hacker config, to make the command output even more useful:

  • by changing the count_deltas setting to true in config.js, the count documents command will also print out the change in the number of documents since the last count

API Additions

Scripting

Get a list of database names:

db.getMongo().getDatabaseNames()

(note that this method is similar - functionality-wise and usage-wise - to the existing db.getCollectionNames() API method and allows for advanced, cross-database scripting in the MongoDB shell)

General

One for finding a single document:

db.collection.find({ ... }).one() == db.collection.findOne({ ... })

Select for selecting fields to return (projection):

db.collection.find({ ... }).select({ name: 1 })

Reverse for descending sort by insertion order (default) or arbitrary field:

db.collection.find({ ... }).reverse()
db.collection.find({ ... }).reverse('createDate')

Last for finding last inserted document (default) or document last by given field:

db.collection.find({ ... }).last()
db.collection.find({ ... }).last('createDate')

Update, Replace, Upsert and Remove can be called on a DBQuery Object:

db.collection.find({ ... }).update({ ... })  // multi update
db.collection.find({ ... }).replace({ ... }) // single replacement
db.collection.find({ ... }).upsert({ ... })  // single upsert
db.collection.find({ ... }).remove()         // multi remove

Sort, limit, and skip through multi updates and removes:

db.collection.find({ ... }).limit(7).update({ ... })
db.collection.find({ ... }).sort({ ... }).skip(1).limit(3).update({ ... })
db.collection.find({ ... }).limit(3).remove()

Note: The performance of multi updates involving a skip or limit may be worse than those without those specifications due to there being absolutely no native support for this feature in MongoDB itself. It should be understood by the user of this software that use of this feature (by calling update on a cursor rather than a collection) is advanced and experimental. The option to do this sort of operation is purely additive to the MongoDB experience with MongoHacker and usage of it is in no way required. Furthermore, its inclusion in this enhancement does not effect the operation of updates invoked through collections and, in practice, is insanely useful.

Aggregation Framework

The aggregation framework is now fluent as well. You can use it as currently documented or via the chainable methods.

Calling aggregate without an array of operations or $operations will make it a match.

// matches every document
db.collection.aggregate()
db.collection.aggregate({})

// matches documents where the "a" is equal to 1
db.collection.aggregate({a: 1})

// matches documents where "a" is greater than 7
db.collection.aggregate({a: {$gt: 7}})

Additional methods can then be chained on top of the inital match in order to make more complicated aggregations.

// Match and project
db.collection.aggregate(<querydoc>).project(<projection>)
db.collection.aggregate({a: 1}).project({a: 1, _id: 0})

// Match, group and sort
db.collection.aggregate({<match>}).group({<group>}).sort({<sort>})
db.test.aggregate().group({_id: '$a', 'sum': {'$sum': 1}}).sort({sum: -1})

Data Generation

For easy and simple random data generation you can utilise these methods below. You can use any of these functions in a loop. For example:

// Inserts 20 documents with random data. 
for (i=1; i<21; i++) { 
    db.collection.insert(
            {
             word: randomWord(), 
             number: randomNumber(), 
             date: randomDate() 
            }
    ); 
}
randomWord

You can specify the length of each word, the number of words, and an optional seeded word in a sentence randomly. Use the optional seed parameter for testing text search.

randomWord(length=5, words=1, seed=undefined)

// Inserts a random sentence consisting of 5 letters per word, 5 words in total, 
// with a probability to insert the word 'needle' in the sentence
db.collection.insert( { words: randomWord(5, 5, 'needle') } )

// Inserts a random word consisting of 16 letters
db.collection.insert( { words: randomWord(16) } )
randomNumber

You can specify maximum number to be randomly generated (exclusive)

randomNumber(max=100)

// Inserts a random number in the range of 0 or 1. 
db.collection.insert( { number: randomNumber(2) } )

// Inserts a random number in the range of 0 or 999. 
db.collection.insert( { number: randomNumber(1000) } )
randomDate

You can specify start and end dates range to be randomly generated. (exclusive)

randomDate(start= <2 years ago> , end=Date() )

// Inserts a random date object in the range of 1st January 2016 to 1st February 2016
db.collection.insert( { date: randomDate(ISODate("2016-01-01T00:00:00"), ISODate("2016-02-01T00:00:00")) })

// If today is 19th May 2016 and you specify only the start of the day, 
// this will generate random date object between 00:00:00 to current time.  
db.collection.insert( { date: randomDate(ISODate("2016-05-19T00:00:00")) })

Helpers

General Shell Helpers

  • findCommand('search') list commands that match the search string

Aggregation Framework Helpers -- on collections

  • Group and Count: gcount(group_field, filter)
  • Group and Sum: gsum(group_field, sum_field, filter)
  • Group and Average: gavg(group_field, avg_field, filter)

Run function on some/all databases

runOnDbs(/db_names_regexp/, function(db) {
    // callback is ran for each database which name matches regular expression
    // db is that selected database
});

Recent Changes

See CHANGELOG.md for a list of changes from previous versions of Mongo Hacker.

A very special thanks to all of the contributors to Mongo Hacker.

Disclaimer

This software is not supported by MongoDB, Inc. under any of their commercial support subscriptions or otherwise. Any usage of Mongo Hacker is at your own risk. Bug reports, feature requests, and questions can be posted in the Issues section on GitHub.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].