Created
June 1, 2018 12:06
-
-
Save wyllie/f60e272f1ad871ad34c8d4feb75f1db8 to your computer and use it in GitHub Desktop.
Common Mongo cli commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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