Docs Menu
Docs Home
/ / /
Laravel MongoDB

Usage Examples

On this page

  • Overview
  • How to Use the Usage Examples
  • Before You Get Started
  • Run the Usage Example
  • Usage Example List

Usage examples show runnable code examples to demonstrate frequently used MongoDB operations. Each usage example includes the following components:

  • Explanation of the MongoDB operation

  • Example code that you can run from an application controller

  • Output displayed by the print statement

To learn how to add a usage example to your Laravel application and view the expected output, see the following sections:

  • Before You Get Started

  • Run the Usage Example

You can run the usage examples from your own Laravel application or from the my-app application created in the Quick Start guide.

The usage examples are designed to run operations on a MongoDB deployment that contains the MongoDB Atlas sample datasets. Before running the usage examples, ensure that you load the sample data into the MongoDB cluster to which your application connects. Otherwise, the operation output might not match the text included in the VIEW OUTPUT tab of the usage example page.

Unless otherwise mentioned, usage examples use the Movie.php model class created in the Quick Start to demonstrate operations on the movies MongoDB collection.

Tip

For instructions on loading the sample data into a MongoDB cluster, see Load Sample Data in the Atlas documentation.

Each usage example page includes sample code that demonstrates a MongoDB operation and prints a result. To run the operation, you can copy the sample code to a controller endpoint in your Laravel application.

To view the expected output of the operation, you can add a web route to your application that calls the controller function and returns the result to a web interface.

See code examples of the following operations in this section:

Back

Next Steps

Next

Find a Document