Skip to content

Instantly share code, notes, and snippets.

@cardoni
Last active August 29, 2015 14:16
Show Gist options
  • Save cardoni/8cba116bde9abe1a6d1f to your computer and use it in GitHub Desktop.
Save cardoni/8cba116bde9abe1a6d1f to your computer and use it in GitHub Desktop.
Useful Mongo Shell Queries
// Returns an Array of all Mongo Collections
db.getCollectionNames();
// Returns Each Mongo Collection w/ Count
db.getCollectionNames().forEach( function ( col ) { print( col, db.getCollection( col ).stats()[ 'count' ] ) } );
// Regex Searching ( w/ Pretty Printing )
db.<collection_name_here>.find( { name: { $regex: /^regex_to_match_on_here/i } } ).pretty();
// Most-Recently-Added Record in Collection ( w/ Pretty Printing )
db.<collection_name_here>.find().sort( { _id: -1 } ).limit( 1 ).pretty();
@cardoni
Copy link
Author

cardoni commented Feb 25, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment