Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amaui-org/amaui-mongo
Mongo
https://github.com/amaui-org/amaui-mongo
amaui back-end backend express expressjs javascript js mongo mongodb node nodejs typescript utils web
Last synced: about 2 months ago
JSON representation
Mongo
- Host: GitHub
- URL: https://github.com/amaui-org/amaui-mongo
- Owner: amaui-org
- License: mit
- Created: 2022-02-03T16:05:19.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-16T15:28:52.000Z (6 months ago)
- Last Synced: 2024-09-23T02:18:00.429Z (3 months ago)
- Topics: amaui, back-end, backend, express, expressjs, javascript, js, mongo, mongodb, node, nodejs, typescript, utils, web
- Language: TypeScript
- Homepage: https://docs.amaui.me/library/mongo
- Size: 222 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
amaui Mongo
Mongo
MIT license
Production ready
100% test cov
Nodejs
Very simple code
Modern code
Junior friendly
Typescript
Made with :yellow_heart:
## Getting started
### Add
```sh
yarn add @amaui/mongo
```Add `mongodb` as a peer dependency
```sh
yarn add mongodb
```### Use
```javascript
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
```sh
yarn
```Test
```sh
yarn test
```#### One time local setup
Install docker and docker-compose
- https://docs.docker.com/get-docker
- https://docs.docker.com/compose/installMake docker containers
```sh
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
```sh
yarn build
```