README
hinos-mongo
A plugin manages mongodb connection for hinos
Install
npm i hinos-mongo -S
Examples
Typescript
Config mongo information
import { Mongo } from 'hinos-mongo';
Mongo({
url: 'mongodb://localhost:27017/conn'
});
Mongo({
key: 'connection1'
url: 'mongodb://localhost:27017/conn2'
});
Use in service file
import { MONGO, Mongo, Uuid, Collection } from 'hinos-mongo';
@Collection('chart')
export class Chart {
_id?: Uuid;
name?: string;
des?: string;
created_at?: Date;
updated_at?: Date;
}
export class ChartService {
@MONGO()
static mongo: Mongo;
@MONGO('connection1')
static mongo1: Mongo;
static async find(fil: any = {}): Promise<Array<Chart>> {
const rs: Chart[] = await ChartService.mongo.find<Chart>(Chart, fil);
return rs;
}
}