Coder Social home page Coder Social logo

bun-mongodb-version-project's Introduction

MongoDB Versioning Using bun.sh and Typescript

This project demonstrates how to implement document versioning in MongoDB using TypeScript. We use bun.sh to manage our project dependencies and MongoClient for MongoDB. Docker is used to create a local MongoDB instance for testing.

Prerequisites

Ensure you have the following installed on your system:

Getting Started

Cloning the Repository

First, clone this repository to your local machine:

git clone <repository-url>
cd my-versioning-project

Installing Dependencies

Install the required dependencies using Bun:

bun install

Setting Up Environment Variables

Create a .env file in the project root and add the following variables:

MONGODB_URL="mongodb://root:example@localhost:27017"
DB_NAME="my-versioning-project"

Setting Up MongoDB

Create a docker-compose.yml file in the project root to set up MongoDB and Mongo Express:

version: '3.8'

services:
  mongodb:
    image: mongo:latest
    container_name: mongodb
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

networks:
  default:
    name: mongodb_network

Start the MongoDB and Mongo Express services:

docker-compose up -d

Verify the containers are running:

docker ps

Running the Project

Run the project using Bun:

bun run src/index.ts

Project Structure

  • src/index.ts: Main entry point for the project.
  • src/services/listingService.ts: Contains the logic for connecting to MongoDB, creating listings, updating listings, and retrieving listing versions.
  • src/models/listing.ts: Defines the TypeScript types for listings and listing versions.
  • src/services/listingService.test.ts: Contains tests for the listing service functions.

Running Tests

To run tests:

bun test

Code Details

Connecting to MongoDB

In src/services/listingService.ts, we define a connectDB function to connect to the MongoDB instance.

Creating and Updating Listings

We define functions to create and update listings in src/services/listingService.ts.

Test Cases

Refer to the src/services/listingService.test.ts file for detailed test cases that ensure the listing service works correctly. The test file includes cases for creating a new listing, updating a listing, retrieving listing versions, and getting a listing by ID.

bun-mongodb-version-project's People

Contributors

ayomikuolatunji avatar

Watchers

 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.