--- title: "Retrieving Data from MongoDB | Docs" description: "This walkthrough shows you how to retrieve data from MongoDB with Node and Express." url: https://www.zinggrid.com/docs/data/mongodb --- ```text experiment_id: web-retrieval-v1 fixture_id: /docs/data/mongodb.md mode: provenance representation: markdown origin_response_id: 5867d1dab6e34e5e14f805896bcebcd6 version: 2026-10-21 version_created_at_utc: 2026-10-21T20:42:35.667Z version_nonce: 43a168c085f565fafe1f9c4d28751ad0 generated_at_utc: 2026-11-08T23:36:15.626Z response_nonce: 74ced2e6229b1a95cd1b58648259141b ``` # Retrieving Data from MongoDB In this guide, we'll walk you through how to retrieve data from MongoDB with Node/Express and incorporate it in your grid. > **Note:** In the examples below, we are using MongoDB with Node and Express. We assume that you have MongoDB installed and are running a local instance of your database. If not, refer to the [MongoDB Documentation](https://docs.mongodb.com/manual/tutorial/getting-started/). For our example, we set up a database `mydb`, which has the collection `users` with 3 documents: ```javascript { name: "Tim", age: 21 }, { name: "Alice", age: 30 }, { name: "Henry", age: 45 } ``` ## Connecting to the Database From the command line, we'll start a mongod process and pass in our database directory, like so: `mongod --dbpath=` Then, in our server.js file, we'll create a connection to the server and our database `mydb`, like so: ```javascript var MongoClient = require('mongodb').MongoClient; var express = require('express'); var app = express(); var url = 'mongodb://localhost:27017'; MongoClient.connect(url, function(err, client) { db = client.db('mydb'); }); ``` ## Populating the Grid To fetch the documents in the `users` collection to use in our grid, we'll create a route path at `/mydb`, which has the array of documents. ```javascript app.get('/mydb', function(req, res) { db.collection('users').find({}).toArray(function(err, docs) { res.send(docs); }); }) ``` Now in our HTML file, we can create our grid and set the `src` attribute to this URL to read from the database. ```html ``` Then, we'll run our server from the command line with: ``` node server.js ``` ## MongoDB Grid Here is our complete grid pulling in data from our MongoDB database: [Example code](https://app.zingsoft.com/demos/embed/N7Y400QR) ## Customizing the Grid By default, MongoDB adds an **_id** field for each document. If you don't want to include a certain field in your grid, you can specify this using `` and ``. Below, we show only the **name** field of our documents: [Example code](https://app.zingsoft.com/demos/embed/DDRV8ONU)