@amaui/mongo
TypeScript icon, indicating that this package has built-in type declarations

1.1.32 • Public • Published

amaui logo

amaui Mongo

Mongo


MIT license     Production ready     100% test cov     Nodejs

Very simple code     Modern code     Junior friendly     Typescript     Made with 💛


Getting started

Add

yarn add @amaui/mongo

Add mongodb as a peer dependency

yarn add mongodb

Use

  import { Mongo, BaseCollection } from '@amaui/mongo';
  // Make if you wanna a config file and
  // inside of it add all the process.env related props
  import Config from './config';

  // Make a new mongo instance
  const mongo = new Mongo({
    uri: Config.db.mongo.uri,
    name: Config.db.mongo.name,
  });

  await mongo.connection;

  // Make a collection class
  class TodoCollection extends BaseCollection {

    public constructor() {
      super('todos', mongo);
    }

  }

  const todoCollection = new TodoCollection();

  // Add
  const todoCreated = await todoCollection.addOne({
    name: 'todo',
    description: 'description'
  });

  // Find one
  const todo = await aCollection.findOne({
    _id: todoCreated._id
  });

  todo;

  // {
  //   _id: ObjectId('407f191e810c19729de860ea'),
  //   name: 'todo',
  //   description: 'description',
  //   added_at: 1777044477
  // }

  // etc.

Dev

Install

yarn

Test

yarn test

One time local setup

Install docker and docker-compose

Make docker containers

yarn docker

(mac) Add lines below to /private/etc/hosts

127.0.0.1   mongo1
127.0.0.1   mongo2
127.0.0.1   mongo3
127.0.0.1   mongo1-test
127.0.0.1   mongo2-test
127.0.0.1   mongo3-test

Prod

Build

yarn build

Package Sidebar

Install

npm i @amaui/mongo

Weekly Downloads

83

Version

1.1.32

License

MIT

Unpacked Size

104 kB

Total Files

15

Last publish

Collaborators

  • lazareric