Code Monkey home page Code Monkey logo

mongo-search's Introduction


MongoDB Text Search With Node.js

Fuzzy Text Search And Autocompletion With MongoDB And Node.js

Features

  • 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

Tech Stack

Usage

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_USERNAME and MONGODB_PASSWORD in .env.atlas
  • Create API Key for your project
    1. Go to Project Settings
    2. Select Access Manager
    3. Select API Keys
    4. Create API Key
    5. Set Project Permissions to Project Search Index Editor
    6. Set MONGODB_ATLAS_PUBLIC_KEY and MONGODB_ATLAS_PRIVATE_KEY in .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)

Codebase

  • 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)

mongo-search's People

Contributors

flolu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.