Docs Menu

Docs HomeStart with Guides

Read Data in MongoDB

In this guide, you will learn how to retrieve data from MongoDB.

Time required: 10 minutes

  • A connection string to your MongoDB deployment.

  • Sample datasets loaded into your cluster.

  • An installed MongoDB Driver.

1

In this code block there is a comment to replace the connection URI with your own. Make sure to replace the URI string with your Atlas connection string.

2

Switch to the database and collection you want to query. In this case you will use the sample_guides database and planets collection.

3
4
5

Here is the complete code followed by sample output.

Note

Your ObjectId values will differ from those shown.

If you successfully completed the procedure in this guide, you have retrieved data from MongoDB.

In the next guide, you'll learn how to retrieve data from MongoDB using criteria.

For other CRUD guides:

What's Next
Read Data from MongoDB With Queries
15 mins

Use a query to specify which documents to retrieve documents in MongoDB.

Start Guide
Chapter 2
CRUD
  • Add a MongoDB Driver
  • Read Data in MongoDB
  • Read Data from MongoDB With Queries
  • Read Data using Operators and Compound Queries
  • Insert Data into MongoDB
  • Update Data in MongoDB
  • Delete Data from MongoDB
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.