To conduct the first demo in the Instruct session on NoSQL you can follow along with the code below.
This MongoDB demo creates a database, inserts data and finds it.
All these commands are to be typed in sequentially into the command prompt. Please ensure that your MongoDB instance is running before starting.
If you are unsure how to get an instance of MongoDB running please view the Session Resources – NoSQL Explained – Running an MongoDB instance page for details on how to get an instance of MongoDB running on your machine.
We are going to run this demo from the MongoDB command prompt, run the following command.
This code will start an instance of the MongoDB command prompt which will connect to an instance of MongoDB server running on localhost and listening on the default port 27017.
To connect to an instance of MongoDB running on another server include the machine name and port as command parameters like this.
Now for a few quick demo items, type the following commands in sequence to create a database, insert a record and find it.
Congratulations you have successfully created a new database which contains a users collection.
You have also successfully inserted two users into the users collection, done a few finds, updated the user documents and removed a user document from the users collection.
Proceed to demo two to walk through working with Mongo indexes.