Storing and retrieving data with MongoDB

In this recipe, we will look at basic CRUD operations with MongoDB. We will learn how to create databases, store, retrieve, and update stored data. This is a recipe to get started with MongoDB.

Getting ready

Make sure that you have installed and configured MongoDB. You can also use the MongoDB installation on a remote server.

How to do it…

Follow these steps to store and retrieve data with MongoDB:

  1. Open a shell to interact with the Mongo server:
    $ mongo
    
  2. To open a shell on a remote server, use the command given. Replace server_ip and port with the respective values:
    $ mongo server_ip:port/db
    
  3. To create and start using a new database, type use dbname. Since schemas in MongoDB are dynamic, you do not need to create ...

Get Ubuntu Server Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.