When you are working in a MERN (MongoDB, Express, React, and Node) stack app, you are often required to fetch a JSON of a Mongo collection and use that data on the frontend. With the popularity of NoSQL databases, it’s really simple to fetch data from a Mongo collection via a React app through an express server.

This guide walks you through the essentials of making an XHR request to an endpoint on an express server to get JSON of a Mongo collection in your MongoDB database.

Setting up the Backend

If you already have an express server with an endpoint where you can fetch your Mongo collection, you can skip this step. If you don’t, you can easily set up an express server using NodeJS using the following steps.

#react #json

Get a JSON of a Mongo Collection with an XHR Request in React
2.60 GEEK