Skip to content

Instantly share code, notes, and snippets.

@Rohithzr
Created June 7, 2024 16:41
Show Gist options
  • Save Rohithzr/4e0c9b02d95444d3041b32ddb006a5b6 to your computer and use it in GitHub Desktop.
Save Rohithzr/4e0c9b02d95444d3041b32ddb006a5b6 to your computer and use it in GitHub Desktop.
#### Objective:
Extend the existing functionality of the CRUD operations and regex-based search by integrating MongoDB to log search queries and user interactions, while PostgreSQL handles the main CRUD operations on item data.
#### Requirements:
1. **Backend (NodeJS + Express):**
- Use PostgreSQL to handle CRUD operations on the items.
- Integrate MongoDB to log each search query along with metadata like the timestamp and user ID (if authentication is implemented).
- Enhance the search functionality in the Express server 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 MongoDB collection to store search logs. Each log entry should include the search term, the date/time of the search, and optionally the user ID.
3. **Frontend (ReactJS):**
- Maintain the existing UI components for displaying and managing items.
- Update the search functionality to log each search action to the MongoDB database 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. This involves inserting a document into a MongoDB collection 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. Make sure that 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, potentially 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.
This task will effectively test a developer's skills in managing multiple databases, handling complex backend logic, and integrating frontend interactions with backend services. It also provides a practical scenario where SQL and NoSQL databases are used together, reflecting a real-world application structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment