Skip to content

Instantly share code, notes, and snippets.

@wyllie
Created June 1, 2018 12:06
Show Gist options
  • Save wyllie/f60e272f1ad871ad34c8d4feb75f1db8 to your computer and use it in GitHub Desktop.
Save wyllie/f60e272f1ad871ad34c8d4feb75f1db8 to your computer and use it in GitHub Desktop.
Common Mongo cli commands
# these are some common mongodb cli commands
# Get help
MongoDB Enterprise > help
# get a list of databases
show dbs
# get list of collections
show collections
# number of items in a collection (where 'col_name' is the name of the collection)
db.col_name.count()
# query the collection - note that ' and " seem to be interchangable
db.col_name.find({'key': 'value'}) # get all of the matching entries
db.col_name.find({'key': 'value'}).count() # count the matching entries
db.col_name.find({'key': 'value'}).pretty() # pretty print the results
# get a list of distinct values for a particular key
db.col_name.distinct('key')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment