Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krakenui/octopus-mongo
Nodejs library for connect mongodb by KrakenTeam!!!
https://github.com/krakenui/octopus-mongo
mongo mongodb node nodejs
Last synced: 13 days ago
JSON representation
Nodejs library for connect mongodb by KrakenTeam!!!
- Host: GitHub
- URL: https://github.com/krakenui/octopus-mongo
- Owner: krakenui
- Created: 2020-09-15T03:58:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-02T03:56:16.000Z (about 4 years ago)
- Last Synced: 2024-11-24T20:38:26.701Z (about 1 month ago)
- Topics: mongo, mongodb, node, nodejs
- Language: TypeScript
- Homepage: https://docs.krakenui.com/octopus-mongo
- Size: 90.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# octopus-mongo
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]
[npm-image]: http://img.shields.io/npm/v/octopus-mongo.svg?style=flat-square
[npm-url]: http://npmjs.org/package/octopus-mongo
[download-image]: https://img.shields.io/npm/dm/octopus-mongo.svg?style=flat-square
[download-url]: https://npmjs.org/package/octopus-mongo## Install
[![octopus-mongo](https://nodei.co/npm/octopus-mongo.png)](https://npmjs.org/package/octopus-mongo)
```
npm install --save octopus-mongo
```## Features
```
- Define interface wrap for entity
- Define common dbcontext
- Define db connect hub
- Define base repository with repository pattern
```## Install
- Before install require packages:
```
npm install mongoose@^5.9.3
```- Install octopus-mongo
```
npm install octopus-mongo
```## How it work
#### MongoDB context
- using:
```
import { connectMongoDb } from "octopus-mongo";await connectMongoDb();
```- output: `MongoDB connected...`
#### Repository pattern
- Define model schema:
```
import { Schema } from "mongoose";const CategorySchema: Schema = new Schema({
categoryId: {
type: String,
required: true,
},
parentId: {
type: String,
},
name: {
type: String,
required: true,
},
context: {
type: String,
required: true,
},
active: {
type: Boolean,
},
createdBy: {
type: String,
},
updatedBy: {
type: String,
},
createdTime: {
type: Date,
},
updatedTime: {
type: Date,
},
});
```- Define model instance:
```
const Category = model("categories", CategorySchema);
```- Define entity interface:
```
import { IDocument } from "octopus-mongo";interface ICategory extends IDocument {
categoryId: string;
parentId: string;
name: string;
context: string;
active: boolean;
createdBy: string;
updatedBy: string;
createdTime: Date;
updatedTime: Date;
}
```- Declare repository into service to query:
```
import { Repository } from "octopus-mongo";_categoryRepository = Repository(Category);
const allCategories = _categoryRepository.find({});
```