Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

litehex/mongodb

Repository files navigation

MongoDB driver for Node.js

This project uses the official MongoDB driver for Node.js. It is a wrapper around the official driver that provides a more convenient API for use with TypeScript and JavaScript.

Installation

npm install github:litehex/mongodb#dist

Usage

Connecting to MongoDB

import { MongoDB, InitMongo } from "@litehex/mongodb";

InitMongo({
   hostname: "localhost",
   port: 27017,
   username: "root",
   password: "password"
});

export const db = MongoDB.db("testing");

Creating a collection

import { OptionalId, CollectionConfig } from "@litehex/mongodb";
import Collection from "@litehex/mongodb/collection";

export type User = OptionalId<{
   nickname: string;
   email: string;
}>

export class UsersCollection extends Collection<User> {
   getConfig(): CollectionConfig {
      return {
         name: "users",
         database: "testing"
      }
   }

   static doSomething() {
      console.log("Something");
   }
}

License

This project is licensed under the MIT license. See the LICENSE file for more info.