BLOGAnnounced at MongoDB.local NYC 2024: A recap of all announcements and updates — Learn more >

How to Use a Sample Database with MongoDB


When you are developing an application, you usually need some type of data to display while you are building and testing the functionality of the app. When there aren’t any users for your application (other than you or the other programmers who are building it), you need a pre-existing data set to populate its pages and use for testing. This is where a sample database is useful.

What is a Sample Database?

A sample database is a pre-existing dataset that you can use for application or database testing. There are many types of sample databases available for free online. Most are designed for a certain type of database engine. Although the schema of a sample database could be inserted into multiple types of databases, the queries involved to create the database objects and entries will differ.

Even though most relational databases use SQL, the syntax of queries can differ, even between different versions of the same database engine. MySQL is an example of a database with a current data dump format that will not work with older versions of the database.

NoSQL really only means "not only SQL." Every NoSQL database uses a unique syntax and API for querying and loading data. So, having a sample database that matches your NoSQL database is even more important.

What Sample Datasets are Available for MongoDB?

There are many datasets to choose from if you are looking for sample or testing data in JSON format for your MongoDB database. But if you have an Atlas account, you don't have to look very far for the data you need. Atlas has eight available sample datasets and makes it easy to load that sample data directly into your cluster. With these datasets, you can test your application or skills at writing aggregation queries.

Here are the sample datasets that Atlas provides:

  • AirBnB listings: This is a randomized compilation of AirBnB listings in one MongoDB collection with documents that include fields like listing_url, address, and name. This collection is from the Inside AirBnB website.
  • Analytics data: This database contains three collections: accounts, customers, and transactions. It represents data from a typical financial services company.
  • Geospatial data: This is one collection of data that contains shipwreck data. A single document in this dataset represents an actual shipwreck and contains latitude and longitude data.
  • Movie data: This database contains five collections: comments, movies, sessions, theaters, and users. It represents the data from a social movie review site.
  • Restaurant data: This sample dataset contains two collections: restaurants and neighborhoods. It is designed to help users become familiar with GeoJSON data.
  • Supply store data: This database consists of a single collection called sales. Each document represents a sale from a supply store.
  • Training data: This is a large dataset used in MongoDB training courses. It contains Crunchbase data, official New York City data, flight data, and Citybike data. It contains seven collections: companies, grades, inspections, posts, routes, trips, and zips.
  • Weather data: This consists of a single MongoDB collection called data. Each document in this collection represents a weather report.

How to Load Sample Data into Your MongoDB Atlas Cluster

There are two ways to load your sample data into your Atlas Cluster. You can either use the Clusters view or the Data Explorer tutorial below.

Option 1: Loading Sample Data from the Clusters View


Log into Atlas. The default view is the Clusters view. Click on the ellipses button in your cluster and then click on Load Sample Dataset.

Creating a cluster in MongoDB Atlas with sample data



A menu will then pop up to check if you are sure. Click the Load Sample Dataset button.

Loading sample dataset in MongoDB Atlas


It will take about a minute for the sample dataset to deploy. Once it does, you will see a message like this:


creating a sample database in mongodb atlas


This loaded every one of the Atlas sample databases into your cluster. Clicking on the Collections buttons like the message suggests will take you to them.


sample collections in mongodb atlas



Option 2: Loading Sample Data from the Data Explorer

The other way to load these sample datasets into your cluster is to go to the Clusters view in Atlas and instead of clicking the ellipses button, click on the Collections button.

collections in MongoDB Atlas



If you have no collections, you will see a Load a Sample Dataset button:

explore your data in mongodb atlas



Clicking that button will bring up the same modal. Click the Load Sample Dataset button:


Loading sample dataset in MongoDB Atlas


This will take about a minute. Once it is done, you can browse through all of your new collections.

sample collections in mongodb atlas



Conclusion

Samples databases are a straightforward concept, but important when building and testing your apps. MongoDB makes it simple to create sample databases with eight different data sets easily imported into MongoDB Atlas.


FAQs


Does MongoDB Provide Sample Datasets?

MongoDB Atlas provides sample datasets that you can load into your own database cluster for testing your application. These available sample datasets include analytics, movie, geospatial, sales, and weather data. You can load this data into your cluster in only a few clicks.


How Do I Load Sample Data into My Atlas Cluster?

It is relatively simple to load sample data into your Atlas Cluster. First, you need a cluster to load the data into. Then you can load all the sample datasets that Atlas provides from either the Clusters view or the Data Explorer.


Ready to get started?

Launch a new cluster or migrate to MongoDB Atlas with zero downtime.