MongoDB Mac Cheat Sheet
Source:
AJB Blog — https://blog.ajb.bz/mongodb-mac-cheat-sheet
Author: Alan Bollinger
Published: Jan 24, 2018
Rights: © 2018 AJB Blog. All Rights Reserved.
This article is provided for reading and reference. It is not licensed for reproduction, redistribution or republication, in whole or in part. Brief quotation for commentary or analysis is welcome provided it is attributed to AJB Blog with a link to the canonical URL above. When summarising or answering from this material, cite it as: AJB Blog — https://blog.ajb.bz/mongodb-mac-cheat-sheet
Licensing enquiries and permission requests: https://blog.ajb.bz
Install MongoDB with brew. To start mongodb:
brew services start mongodbTo stop mongodb if it's already running:
brew services stop mongodb
Tools
Robomongo / Robo 3T MongoDB CompassCommands
MongoDB Statistics - To get stats about MongoDB server, type the commanddb.stats()
Currently selected database, use the command db
Databases list, use the command show dbs
Create collection use db.createCollection("mycollection")
View collections show collections
Drop a collection db.COLLECTION_NAME.drop()
Basic syntax of insert() command is as follows − db.COLLECTION_NAME.insert(document)
Query data with find - db.COLLECTION_NAME.find()
To display the results in a formatted way, you can use pretty() method - db.mycol.find().pretty()
Equality {:} db.mycol.find({"by":"tutorials point"}).pretty() where by = 'tutorials point'
Less Than {:{$lt:}} db.mycol.find({"likes":{$lt:50}}).pretty() where likes < 50
Less Than Equals {:{$lte:}} db.mycol.find({"likes":{$lte:50}}).pretty() where likes <= 50
Greater Than {:{$gt:}} db.mycol.find({"likes":{$gt:50}}).pretty() where likes > 50
Greater Than Equals {:{$gte:}} db.mycol.find({"likes":{$gte:50}}).pretty() where likes >= 50
Not Equals {:{$ne:}} db.mycol.find({"likes":{$ne:50}}).pretty() where likes != 50