Skip to content

Instantly share code, notes, and snippets.

@Rohithzr
Created June 8, 2024 15:40
Show Gist options
  • Save Rohithzr/98b9b7fea958a26be1773202b9fd0d72 to your computer and use it in GitHub Desktop.
Save Rohithzr/98b9b7fea958a26be1773202b9fd0d72 to your computer and use it in GitHub Desktop.
#### Requirements:
1. **Backend (NodeJS + Express):**
- Use PostgreSQL to manage CRUD operations on items.
- Integrate MongoDB to log each search query with metadata like the timestamp and user ID (if authentication is implemented).
- Enhance the search functionality to interact with both databases appropriately.
2. **Database Setup:**
- **PostgreSQL:** Continue using PostgreSQL for managing the `items` table with CRUD operations.
- **MongoDB:** Set up a collection to store search logs, including the search term, date/time, and optionally the user ID.
3. **Frontend (ReactJS):**
- Maintain existing UI components for displaying and managing items.
- Update the search functionality to log each search action to MongoDB through the Express API.
#### Steps to Follow:
1. **Backend Setup:**
- Modify the `GET /api/items` route to log search details to MongoDB whenever a search is performed. Insert a document into MongoDB each time the search API is hit.
- Ensure proper configuration and connection handling for both PostgreSQL and MongoDB in the Express app.
2. **Database Configuration:**
- Ensure PostgreSQL is configured for item data management with optimized queries for regex searches.
- Set up MongoDB with appropriate indexing on the search logs collection to optimize query performance for logs retrieval or analysis.
3. **Frontend Setup:**
- Adjust the `ItemList` component to handle search logging. Ensure every search, whether successful or not, triggers a log entry to MongoDB via the backend.
#### Additional Challenges:
- Implement real-time feedback on the frequency of searches for certain items, using MongoDB's aggregation capabilities to summarize recent search activity.
- Provide a dashboard component in React to visualize search trends or log data fetched from MongoDB.
#### Deliverables:
- Source code for the backend with dual database handling.
- Updated React components for item management and search logging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment