- Exact match text search with self-deployed MongoDB
- Fuzzy text search with MongoDB Atlas
- Text autocompletion
- Sort search results by score
- Search through multiple text fields
- Limit search results to specific country code
- Populate database with fake users
- Small user interface for searching
- Node.js
- TypeScript
- Docker
- Self-deployed MongoDB or MongoDB Atlas
Recommended OS: Linux
Requirements: Node.js, Docker
Setup
npm install(Install NPM dependencies for server)
Self Deployed Search
docker-compose -f docker-compose.yml up --build(Start services)npx ts-node fake-data.ts .env.local(Add fake data to MongoDB)mongodb://admin:password@localhost:27017(MongoDB Compass connection URI)- http://localhost:3000/search?query=gilbert (Basic search)
MongoDB Atlas Search
- Create MongoDB Atlas cluster
- Create a user with password and set
MONGODB_USERNAMEandMONGODB_PASSWORDin.env.atlas - Create API Key for your project
- Go to Project Settings
- Select Access Manager
- Select API Keys
- Create API Key
- Set Project Permissions to Project Search Index Editor
- Set
MONGODB_ATLAS_PUBLIC_KEYandMONGODB_ATLAS_PRIVATE_KEYin.env.atlas
docker-compose -f docker-compose.yml up --build(Start services)npx ts-node fake-data.ts .env.atlas(Add fake data to MongoDB)- http://localhost:3001/search?query=gilbert (Fuzzy search)
User interface
cd client && npm install(Install NPM dependencies for client)cd client && npm run dev(Start user interface in development mode, http://localhost:4000)
Cleanup
docker-compose -f docker-compose.yml rm -s -f -v(Stop and remove Docker containers)
self-deployed-api.ts(Node.js API to fetch search results from self-deployed MongoDB)atlas-api.ts(Node.js API to fetch search results from MongoDB Atlas, which has more features)fake-data.ts(Script to populate MongoDB with fake data)util.ts(Utilities for TypeScript and MongoDB)
