Quick-start samples demonstrating how to retrieve data from a MongoDB database via a Node.js/Express Web API and display it using Syncfusion EJ2 PivotView (Pivot Table) across JavaScript (vanilla), TypeScript, Angular, React, Vue, and .NET sample patterns.
- π Project Overview
- π Quick Start
- β¨ Key Features
- π οΈ Supported Platforms & Dependencies
- π§ Project Structure
- π§© Minimal Example (MongoDB API + PivotView)
- βοΈ Configuration & Environment
- π§ͺ Testing & CI
- π€ Contributing
- π License & Support
This repository demonstrates how to connect to a MongoDB database from a Node.js/Express Web API (server) and surface query results to client applications using Syncfusion EJ2 PivotView controls. It includes a vanilla JavaScript client sample and patterns that can be adapted to TypeScript, Angular, React, Vue, and server-side frameworks.
Use cases:
- Lightweight analytics and multidimensional reporting
- Sales/finance pivot reporting from MongoDB collections
- Rapid prototyping of PivotView integrations with MongoDB backends
Repository reference sample: https://github.com/SyncfusionExamples/web-how-to-bind-MongoDB-to-pivot-table
Prerequisites
- Node.js 16+ (LTS recommended)
- MongoDB server (local MongoDB, MongoDB Atlas, or connection string)
- Optional: npm (comes with Node.js) for front-end dependencies
Run the Web API (server)
cd server
npm install
# set environment variable MONGODB_URI or edit config
node index.js
# API runs on the configured port (see server/index.js)Run the front-end sample (vanilla JavaScript)
cd (front-end sample folder) # e.g., src/ or a client sample directory
npm install
npm startFirst success: Open the front-end sample URL (e.g., http://localhost:3000) and confirm the PivotView loads rows from the running Web API.
- MongoDB Node.js integration (
mongodbdriver) in the Express API β - Simple REST endpoint returning JSON consumable by PivotView β
- Vanilla JavaScript client sample binding
ej.pivotview.PivotViewβ - Copy-paste-ready patterns for server β client binding to Syncfusion PivotView β
Why this helps:
- Quickly exposes MongoDB collections to interactive pivot reporting.
- Reusable patterns across modern front-end frameworks.
- Languages: JavaScript/TypeScript (Node.js backend, client)
- Server (
server/package.json):expressβ lightweight web frameworkmongodbβ official MongoDB Node.js drivercorsβ enable cross-origin requests for local testingdotenv(optional) β load environment variables from.env
- Client:
@syncfusion/ej2umbrella or per-framework packages (e.g.,@syncfusion/ej2-pivotview30.x+) - System requirements: Node.js, MongoDB (or Atlas), npm for front-end builds
- server β Node.js/Express Web API that queries MongoDB and returns JSON
- src β front-end sample (vanilla JS/TS) using Syncfusion PivotView
components/β reusable client-side components (e.g.,pivotTable.js)services/β client-side services (e.g.,elasticsearchService.jsadapted for MongoDB)
Entry points:
- API route: index.js or
server/routes/pivot.js(or similar) - Client mount: index.html and main.js or framework equivalents
Server: basic MongoDB query (Node.js, using mongodb driver)
// server/index.js (minimal)
const express = require('express');
const { MongoClient } = require('mongodb');
const app = express();
const port = process.env.PORT || 3001;
const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017/mydb';
app.get('/api/pivotdata', async (req, res) => {
const client = new MongoClient(uri);
try {
await client.connect();
const db = client.db(); // uses db from URI or default
const col = db.collection('sales_sample'); // collection with documents
const cursor = col.find({}, { projection: { Country: 1, Product: 1, Amount: 1, _id: 0 } }).limit(1000);
const rows = await cursor.toArray();
res.json(rows);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch pivot data' });
} finally {
await client.close();
}
});
app.listen(port, () => console.log(`API listening on port ${port}`));Client: bind PivotView (vanilla JS)
<!-- include Syncfusion CSS/JS via CDN or bundle -->
<link href="https://cdn.syncfusion.com/ej2/30.1.42/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.42/ej2-pivotview/styles/material.css" rel="stylesheet" />
<script src="https://cdn.syncfusion.com/ej2/30.1.42/ej2-base/dist/global/ej2-base.min.js"></script>
<script src="https://cdn.syncfusion.com/ej2/30.1.42/ej2-pivotview/dist/global/ej2-pivotview.min.js"></script>
<div id="PivotTable" style="height: 400px;"></div>
<script>
fetch('/api/pivotdata')
.then(r => r.json())
.then(data => {
var pivot = new ej.pivotview.PivotView({
dataSourceSettings: {
dataSource: data,
rows: [{ name: 'Country' }],
columns: [{ name: 'Product' }],
values: [{ name: 'Amount' }]
},
showFieldList: true,
height: 400
});
pivot.appendTo('#PivotTable');
})
.catch(err => console.error('Failed to load pivot data', err));
</script>- MongoDB connection: store credentials securely (environment variables or secret manager). Example connection string formats:
Local:
MONGODB_URI=mongodb://localhost:27017/mydb
Atlas:
MONGODB_URI=mongodb+srv://<user>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority
- Configure environment variables in a
.envfile (usedotenv) or set them in your hosting environment. - CORS: enable for local front-end origins in index.js for development.
Troubleshooting:
- Verify MongoDB user permissions for the queried collection.
- Confirm network access to Atlas (whitelist IPs) or local MongoDB instance.
- Increase query limits or add indexes for large collections.
- Add GitHub Actions to run basic checks:
npm ci/npm run buildfor front-end samplesnpm install/node server/index.jssmoke test for the API
- Suggested jobs:
install dependencies/lint/unit tests(if present)start serverandrun end-to-end checksagainst/api/pivotdata
Contributions welcome. Suggested workflow:
- Fork and create a branch
feature/<desc> - Run the Web API locally and test sample clients
- Open a PR with description, screenshots, and testing steps
This is a commercial product subject to the Syncfusion End User License Agreement (EULA).
Free Community License is available for qualifying users/organizations:
- Annual gross revenue < $1 million USD
- 5 or fewer total developers
- 10 or fewer total employees
The community license allows free use in both internal and commercial applications under these conditions.
No registration or approval is required β just comply with the terms.
Paid Licenses are required for:
- Larger organizations
- Teams exceeding the community license limits
- Priority support, custom patches, or on-premise deployment options
Purchase options and pricing: https://www.syncfusion.com/sales/products
30-day free trial (full features, no credit card required): https://www.syncfusion.com/downloads/essential-js2
Community License details & FAQ: https://www.syncfusion.com/products/communitylicense
Full EULA: https://www.syncfusion.com/eula/es/
Β© 2026 Syncfusion, Inc. All Rights Reserved.