1.0.0 • Published 5 years ago
mission.mongodb v1.0.0
mission.mongodb
Getting Started
import { BaseMongo, Factory, MongoCollection, MongoDbRepo, SchemaRepo, Validator } from 'mission.mongodb';
SchemaRepo.add('test-schema', {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Product set',
type: 'object',
properties: {
id: {
description: 'The unique identifier for a product',
type: 'number',
},
name: {
type: 'string',
},
age: {
type: 'number',
exclusiveMinimum: 0,
},
place: {
type: 'string',
},
},
required: ['id', 'name', 'age'],
});
export class StartUp {
public async start(): Promise<void> {
await MongoDbRepo.connect('mongodb://localhost:27017', { useNewUrlParser: true });
const data = { id: 1, name: 'Natarajan Ganapathi', age: 35, place: 'Namakkal' };
const valid = await Validator.validate('test-schema', data);
if (valid.errors) {
// tslint:disable-next-line:no-console
console.error(valid.errors);
process.exit(1);
}
const res = await Factory.getBo<Table>(Table).insert(data);
await MongoDbRepo.close();
// tslint:disable-next-line:no-console
console.log(res);
}
}
@MongoCollection('mio', 'info')
export class Table extends BaseMongo<any> {
public async insert(data: any) {
const info = await this.collection();
return await info.insertOne(data);
}
}
new StartUp().start().catch((err) => {
// tslint:disable-next-line:no-console
console.error(err);
});
Prerequisites
Installing
Credits
License
1.0.1-dev.1569947117042
5 years ago
1.0.1-dev.1567783552389
5 years ago
1.0.1-dev.1556724266786
5 years ago
1.0.0
5 years ago
1.0.0-dev.1555265716036
5 years ago
0.0.1-dev.1555240179225
5 years ago
0.0.1-dev.1553323061637
5 years ago
0.0.1-alpha.5
5 years ago
0.0.1-dev.1545926419336
5 years ago
0.0.1-alpha.4
6 years ago
0.0.1-alpha.3
6 years ago
0.0.1-alpha.2
6 years ago
0.0.1-alpha.1
6 years ago