vados-mongo

Module help to connect to mongodb for vados

Usage no npm install needed!

<script type="module">
  import vadosMongo from 'https://cdn.skypack.dev/vados-mongo';
</script>

README

vados-mongo

A plugin manages mongodb for vados

Install

npm i vados-mongo -S

Examples

Typescript

Config mongo information

import { Mongo } from 'vados-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 'vados-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;
    }
}