Giter Site home page Giter Site logo

amaui-org / amaui-mongo Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 216 KB

Mongo

Home Page: https://docs.amaui.me/library/mongo

License: MIT License

JavaScript 17.07% TypeScript 82.93%
mongo mongodb backend back-end web javascript node nodejs amaui utils typescript express expressjs js

amaui-mongo's Introduction



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

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.