![Brew install mongo shell](https://loka.nahovitsyn.com/15.jpg)
![brew install mongo shell brew install mongo shell](https://jojozhuang.github.io/assets/images/programming/2032/versionmac.png)
Non SequiturĪs easy as MongoDB was to get up and running, using it definitely makes me feel like a child. Maybe it just adds a layer of novelty for me.
![brew install mongo shell brew install mongo shell](https://jindahan.com/draft/pic/github_contri_170827.png)
I found it much easier to write MongoDB scripts in my SublimeText editor than in the command-line shell.Īnyway, you could have done all of this using the local mongod server but, there's something fun about connecting to and interacting with a remote machine. In fact, I found the Mongo shell rather frustrating so, I created a "test" script and just kept loading it / running it over and over again. Once you load a script using the load() command, there's nothing that prevents you from loading the script again. > Friends collection has been populated with test data.Īt this point, I now have my connection open and my sample data ready to go I can simply start interacting with the hosted MongoDB database: I ran this script in the Shell using the same load() command: Here, I am inserting 10 friend "documents" with randomly-selected ages. Print( "> Friends collection has been populated with test data." ) Set up the randomly genreated friends. Print( "> Friends collection has been reset." )
![brew install mongo shell brew install mongo shell](https://bennadel-cdn.com/resources/uploads/2013/mongolab-testing-4.png)
Clear any existing data from the friends collection. So, I set up another JavaScript file to load up some sample data: friends.js - My Sample Data Script But, I really love this idea of being able to run JavaScript files directly in the Shell. This has re-defined the "db" variable which I can now use to start interacting with the MongoLab. I can then run this script in the Shell using the load() command: Here, I am creating a connection object using the connection string provided on the MongoLab database detail page. Print( "> MongoLab connection and DB defined." ) we can connect and define our own db instance. to start the MongoDB Shell (mongo) with the -nodb flag. Because we are going to be using a remote connection, be sure
![Brew install mongo shell](https://loka.nahovitsyn.com/15.jpg)